I am new to C programming, having a bit of difficulty with a programming exercise, I’m sure it’s just for those who know C, unfortunately you need to play by the rules of the exercise.
Here's the exercise:
Ask the user to request a capital letter. Use nested loops to create a pyramid pattern for example:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
The pattern should extend to the character entered. For example, the preceding pattern will be the input value E. Hint: use external to process strings. Use three inner loops in a row, one to process letters, one to print letters in ascending order, and one to print letters in descending order.
So, I got this far:
#include <stdio.h>
int main(void) {
int rows;
int spaces;
char asc;
char desc;
char input;
printf("Please enter an uppercase letter: ");
scanf("%c", &input);
for (rows = 'A'; rows <= input; rows++) {
for (spaces = input; spaces > rows; spaces--) {
printf(" ");
}
for (asc = 'A'; asc <= rows; asc++) {
printf("%c", asc);
}
for (desc = asc - 2; desc >= rows; desc--) {
printf("%c", desc);
}
printf("\n");
}
return 0;
}
source
share