Saturday, March 10, 2012

Write a C program to print the following Pattern

A) 1      
     1 2
     1 2 3
     1 2 3 4 


#include
#include
void main()
{
int i,j;
clrscr();
for(i=0;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ", j);
}
printf("\n");
}
getch();
}


B)  1
      2 2
      3 3 3
      4 4 4 4 

#include
#include
void main()
{
int i,j;
clrscr();
for(i=0;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ", i);
}
printf("\n");
}
getch();
}





No comments:

Post a Comment