Sunday, January 8, 2012

Programs on Patterns Using C Language


Two programs on pattern using C Language are given below


1
333
55555
7777777
999999999
7777777
55555
333
1


#include<stdio.h>
void main()
{
int m,n,b=1;
for(m=0; m<5; m++)
{
for(n=0; n<m*2+1; n++)
{
 printf("%d",b);
}
b=b+2;
printf("\n");
}
b=b-4;
for(m=0; m<4; m++)
{
for(n=0; n< 7 - m*2; n++)
{
printf("%d",b);
}
b=b-2;
printf("\n");
}
getch();
}


Display the pattern using C Language program.


1
2_2
3_3_3
4_4_4_4
5_5_5_5_5
4_4_4_4
3_3_3
2_2
1




#include<stdio.h>
void main()
{
int m,n,b=1;
for(m=0; m< 5; m++)
{
for(n=0; n< m*2+1; n++)
{
if(n%2==0)
 printf("%d",b);
 else
 printf(" ");
}
b=b+1;
printf("\n");
}
b=b-2;
for(m=0; m< 4; m++)
{
for(n=0; n< 7 - m*2; n++)
{
if(n%2==0)
 printf("%d",b);
 else
 printf(" ");
}
b=b-1;
printf("\n");
}
getch();
}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner