In this section we will see how to print a number 100 times in C. There are some constraints. We cannot use loops, recursions or macro expansions.
To solve this problem we will use the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions are like below.
Example
#include <stdio.h> #include <setjmp.h> jmp_buf buf; main() { int x = 1; setjmp(buf); //set the jump position using buf printf("5"); // Prints a number x++; if (x <= 100) longjmp(buf, 1); // Jump to the point located by setjmp }
Output
5555555555555555555555555555555555555555555555555555555555555555555555555555 555555555555555555555555