Tobey Marshall Tobey Marshall - 1 month ago 7
C Question

Write a in c program using loop control to produce the following output

Write a program in c using loop control to produce the following output

A B C D E F G
A B C D E F
A B C D E
A B C D
A B C
A B
A


i have written this which outouts inverted pyramid using number; but in stand of number i want to output in alphabet shown above please help me

#include <stdio.h>
int main()
{
int i, j, rows;

printf("Enter the number of rows: ");
scanf("%d",&rows);

for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("%d ",j);
}
printf("\n");
}

return 0;
}

Answer

You can try this:

char i;
    for ( i = 'G'; i >= 'A'; i--) {
        for (char j = 'A'; j <= i; j++) {
            printf("%c ",j);
        }
        printf("\n");
    }

output:

A B C D E F G 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A
Comments