Wednesday, 5 October 2011

patterns in C language


/*   Pattern 1:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5*/




#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
printf("\nPattern 1:\n\n");
for(x=1;x<=5;x++)
{
for(y=1;y<=x;y++)
{
printf("%d ",y);
}
printf("\n");
}
getch();
printf("\n\n\n\n\nPattern 2:\n\n");




/* Pattern 2:
1
2 1
3 2 1
4 3 2 1
5 4 3 2 1    */


for(x=1;x<=5;x++)
{
for(y=x;y>=1;y--)
{
printf("%d ",y);
}
printf("\n");
}
getch();
}

No comments:

Post a Comment