Display pattern using C
/* Write a program to display the following pattern
ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A
*/
#include<stdio.h>
void main()
{
char ch;
int i,j,m;
printf("Enter the height of the pattern " );
scanf("%d",&m);
for(i=0;i<=m/2;i++)
{
ch='A';
for(j=0;j<m;j++)
{
if(j>m/2-i && j<m/2+i)
printf(" ");
else
printf("%c",ch);
if(j>=m/2)
ch--;
else
ch++;
}
printf("\n");
}
}
ABCDEDCBA
ABCD DCBA
ABC CBA
AB BA
A A
*/
#include<stdio.h>
void main()
{
char ch;
int i,j,m;
printf("Enter the height of the pattern " );
scanf("%d",&m);
for(i=0;i<=m/2;i++)
{
ch='A';
for(j=0;j<m;j++)
{
if(j>m/2-i && j<m/2+i)
printf(" ");
else
printf("%c",ch);
if(j>=m/2)
ch--;
else
ch++;
}
printf("\n");
}
}
Comments
Post a Comment