Home > Backend Development > C++ > In C language, print a number 100 times without using loops, recursion and macro expansion.

In C language, print a number 100 times without using loops, recursion and macro expansion.

WBOY
Release: 2023-08-27 08:29:13
forward
1155 people have browsed it

In C language, print a number 100 times without using loops, recursion and macro expansion.

In this section, we will see how to print a number 100 times in C language. There are some restrictions. We cannot use loops, recursion or macro expansion.

To solve this problem, we will use setjump and longjump in C language. setjump() and longjump() are located in the setjmp.h library. The syntax of these two functions is as follows.

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
}
Copy after login

Output

5555555555555555555555555555555555555555555555555555555555555555555555555555
555555555555555555555555
Copy after login

The above is the detailed content of In C language, print a number 100 times without using loops, recursion and macro expansion.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template