How to print N times without using loops or recursion ?

How to print “Hello” N times (where N is user input) without using loop or recursion or goto.

Input : N, that represent the number of times you want to print the statement.
Output : Statement for N times

First we create a class. After that we need initialize the constructor of the class by writing the statement you want to print inside a cout/print statement. The basic idea used here that “The no. of times you create the object of the class, the constructor of the that class is called that many times.”

filter_none

edit
close

play_arrow

link
brightness_4
code

// CPP program to print a sentence N times
// without loop and recursion.
// Author : Rohan Prasad
#include <iostream>
using namespace std;
class Print {
  
public:
    Print()
    {
        cout << "Hello" << endl;
    }
};
  
int main()
{
    int N = 5;
    Print a[N];
    return 0;
}

chevron_right


Output:

Hello
Hello
Hello
Hello
Hello


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


5


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.