Program:
#include<stdio.h>
int main()
{
int i,j,k,n,s;
char ch='A'-1;
printf("How many lines: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(s=1;s<=n-i;s++)
{
printf(" ");
}
for(j=1,k=1;j<=2*i-1;j++,k=k+2)
{
printf("%2c",ch+k);
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(s=1;s<=n-i;s++)
{
printf(" ");
}
for(j=1,k=1;j<=2*i-1;j++,k=k+2)
{
printf("%2c",ch+k);
}
printf("\n");
}
return 0;
}
Output:
#include<stdio.h>
int main()
{
int i,j,k,n,s;
char ch='A'-1;
printf("How many lines: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(s=1;s<=n-i;s++)
{
printf(" ");
}
for(j=1,k=1;j<=2*i-1;j++,k=k+2)
{
printf("%2c",ch+k);
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(s=1;s<=n-i;s++)
{
printf(" ");
}
for(j=1,k=1;j<=2*i-1;j++,k=k+2)
{
printf("%2c",ch+k);
}
printf("\n");
}
return 0;
}
Output:
No comments:
Post a Comment