Question:
C program that will display this output:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
C program that will display this output:
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
Solution:
C program:
#include<stdio.h>
void main()
{
int no_of_lines, alphabet = 65, i, count, j;
printf("\nenter the number of lines you want to print\t:");
scanf("%d",&no_of_lines);
count=2*no_of_lines;
for(j=0;j<no_of_lines;j++)
{
if(j==0)
{
printf("\n\n");
for(i=0;i<count;i++)
{
if(i<no_of_lines)
{
printf(" %c", alphabet++);
}
else if(i == no_of_lines)
{
alphabet--;
}
else
{
printf(" %c",--alphabet);
}
}
}
else
{
printf("\n");
//printf("\nnothing\n");
for(i=0;i<count-2*j;i++)
{
if(i<no_of_lines-j)
{
printf(" %c", alphabet++);
}
else
{
printf(" %c",--alphabet);
}
}
}
}
}
OUTPUT:
enter the number of lines you want to print : 7
A B C D E F G F E D C B A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
A B C D E F F E D C B A
A B C D E E D C B A
A B C D D C B A
A B C C B A
A B B A
A A
Your question is different and answer is different (if I'm not wrong🙏)
ReplyDelete