Write source code (program) in C. Your source code should have adequate comments
ID: 3817819 • Letter: W
Question
Write source code (program) in C. Your source code should have adequate comments. Have a program request the user to enter an uppercase letter. Use nested loops t produce a pyramid like this:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
The pattern should extend to the character entered. For example, the preceding pattern would result from an imput value of F.
Hint: Use an outer loop to handle the rows. Use three inner loops in a row, one to handle the spaces, one for printng letters in descending order.
Explanation / Answer
Executable code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int ch=65;
int i,j,k,m;
clrscr();
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
printf(" ");
for(k=1;k<=i;k++)
printf("%c",ch++);
ch--;
for(m=1;m<i;m++)
printf("%c",--ch);
printf(" ");
ch=65;
}
getch();
}
Output:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.