Saturday, October 15, 2011

A C++ program that use nested loop to print lines 1 to 50

C++ Program :-



#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
int num1,num2,num3=1;
for(num1=1;num1<=5;num1++)
{
cout<<endl;
for(num2=num3;num2<num3+10;num2++)
{
cout<<"  "<<num2;
}


num3+=10;
}
getch();
}

OUTPUT:-

1 2 3 4 5 6 7 8 9 10
11 12 13 14 15..... 20
21..... ....................30
31...........................40
41...........................50

5 comments:

  1. Write in comments if you have any questions about this program I will answer as early as possible.

    ReplyDelete
  2. Yeh tO bhT Aasan PrOgram hai .. :P :P

    ReplyDelete
  3. then dats gud bro try advance level yar :-)

    ReplyDelete
  4. BRO plz tell me how to output that similar program using just 1 single FOR loop

    ReplyDelete
  5. for(n=1;n<=50;n++)
    {
    printf("%d ",n);
    if(n%10==0)
    printf("\n");
    }

    ReplyDelete