How can I print 1 to 100 in C++ without a loop, GOTO or recursion?

*Gasp*

Answer by Brian Bi:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#include <csetjmp>
#include <iostream>
using namespace std;
int main()
{
    jmp_buf b;
    int x = 1;
    setjmp(b);
    cout << x++ << endl;
    if (x <= 100)
        longjmp(b, 1);
    return 0;
}

Usually, when this problem is posed, use of setjmp()/longjmp() is disallowed as well.

How can I print 1 to 100 in C++ without a loop, GOTO or recursion?

Iklan

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s