Friday, July 16, 2004

I friend asked me this question.

Write a C++ program that prints "Hello" hundred times without using any loop or recursion statements and obviously without writing the printing statement hundred times.

And the solution is



#include
using namespace std;

class Show
{
public:
show(){cout <<"Hello" << endl;};
};

int main()
{
Show s[100];
}



I just do not know why someone will ever need this but found it very amuzing. He even went as far as to optimize it by adding the same cout << "Hello" to the destructor and only creating 50 objects instead of 100!!!!!!!

No comments: