Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote