Wednesday, March 23, 2011

Control Satement in C language

/*
Write a program to print
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5.

*/
# include "stdio.h"
int main()
{
int nNumber;
int nLoop1,nLoop2;
printf("Enter the last number you want to display\n");
scanf("%d",&nNumber);

for(nLoop1=1;nLoop1<=nNumber;nLoop1++)
{
for(nLoop2 = nLoop1;nLoop2 > 0; nLoop2--)
{
printf("%d \t",nLoop1);
}

printf("\n");
}
return 0;
}

OUTPUT:


Enter the last number you want to display
10
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10
Press any key to continue . . .

No comments:

Post a Comment