Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to print a number 100 times without using loop and recursion in C?

  • Difficulty Level : Medium
  • Last Updated : 10 Oct, 2017

It is possible to solve this problem using loop or a recursion method but what if both are not allowed?

A simple solution is to write the number 100 times in cout statement. A better solution is to use #define directive (Macro expansion)

Take a step-up from those "Hello World" programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.




// CPP program to print "1" 100 times.
  
// Prints 1 only once
#define a cout<<"1"<<endl;
  
// Puts "a" 10 times
#define b a a a a a a a a a a
  
// Puts "b" 10 times
#define c b b b b b b b b b b
  
int main()
{
  c;
  return 0;
}

Output: 100 times 1.

This article is contributed by Aditya Rakhecha. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Recommended Articles
Page :