WRITE A C PROGRAM TO PRINT THE PATTERN:
1
2 3 2
3 4 5 4 3
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,x=1,l=0,m=1,n,now,y;
printf("Enter the number of row: ");
scanf("%d",&n);
printf("Your pattern is: \n");
for(i=1;i<=n;i++)
{
x=i+l;
row=n-m;
for(y=1;y<=roe;y++)
printf(" ");
for(j=i;j<=x;j++)
printf("%d",j);
for(k=x-1;k>=i;k--)
printf("%d",k);
printf("\n");
l++;
m++;
}
getch();
}
Output:
Enter the number of row: 3
your pattern is:
1
2 3 2
3 4 5 4 3
1
2 3 2
3 4 5 4 3
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,x=1,l=0,m=1,n,now,y;
printf("Enter the number of row: ");
scanf("%d",&n);
printf("Your pattern is: \n");
for(i=1;i<=n;i++)
{
x=i+l;
row=n-m;
for(y=1;y<=roe;y++)
printf(" ");
for(j=i;j<=x;j++)
printf("%d",j);
for(k=x-1;k>=i;k--)
printf("%d",k);
printf("\n");
l++;
m++;
}
getch();
}
Output:
Enter the number of row: 3
your pattern is:
1
2 3 2
3 4 5 4 3
No comments:
Post a Comment