Open In App

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

Last Updated : 02 Mar, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

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

CPP
// 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. 

Time Complexity: O(1). As the program prints "1" only once and it has a constant time complexity of O(1).

Space Complexity: O(1). As no extra space is used in the program, the space complexity is constant and O(1).


Next Article
Article Tags :
Practice Tags :

Similar Reads