Translate

Search This Blog

Tuesday, 1 April 2014

Write a program in C top print the pattern

pattern :
                     1
                     2 2
                    3 3 3
                   4 4 4 4
                  5 5 5 5 5

Code :

#include <stdio.h>
#include <conio.h>
void main()
{
int r,s,c;
clrscr();
for(r=1;r<=5;r++)
{
for(s=1;s<=(5-r);s++)
printf(" ");
for(c=1;c<=r;c++)
printf("%2d",r);
printf("\n");
}
getch();
}


output:
                   
                      1
                     2 2
                    3 3 3
                   4 4 4 4
                  5 5 5 5 5

No comments:

Post a Comment