Translate

Labels

Saturday, 5 January 2013

PRINTING THE NUMBER WITH RESPECT TO THAT NUMBER

Write a program to print 1 once,2 twice in the next line,3 thrice in the next line and continues up to 10, that is 10 written ten times.This problem requires two loops;the outer loop controls the number of the times the inner loop has to be repeated.Each time the inner loop is executed, the number of times it gets repeated depends on the outer loop control variable,s value.The program is as follows:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
i=1;
while(i<=10)
{
j=1;
while(j<=1)
{
printf("%d",i);
j++;
}
printf("\n");
i++;
}

 The output is as follows:
1
22
333
4444
55555
666666
7777777
88888888
999999999
10101010101010101010

The inner loop of the above program is executed for i number of times where i is the control variable of the outer loop.

No comments: