Saturday, January 11, 2014

Printing pattern-5

1
23
456
78910

This pattern is very much similar to the pattern which is earlier discussed.

Outer Loop controls no. of lines to be printed which are 4.
Inner Loop controls the digits printed in each line.
In line no.1 we have only 1 digit printed.
In line no.2 we have 2 digits printed.
and so on.
Next digit is increment of previous digits, so we take a counter to keep count of next digit to be printed.

Outer Loop
for(i=1;i<=4;i++)

Inner Loop
for(j=1;j<=i;j++)

#include<stdio.h>
int main()
{
       int i,j count;
       count=1;

       for(i=1;i<=4;i++)
      {
             for(j=1;j<=i;j++)
            {
                   printf("%d",count);
                   count++;
            }
            printf("\n");
      }
   return 0;
 }



No comments:

Post a Comment