Wednesday, October 30, 2013

Print 1 to 100 without using any loops

Program:

#include<iostream.h>
void main()
{
   static int i;
   i++;
   if(i==101)
   {
      getch();
      exit(0);
   }
   else
   {
      cout<<"\n"<<i;
      main();
   }
}

Output:
1
2
3
4
5
.
.
.
.
.
100

No comments: