Now I'm reading C Premier Plus by Stephen Prata and there's an exercise 4 in chapter 6 which has no solution in the book, so I can't check if I did it properly. My code works like it should, but I want to know maybe there are some better or cleaner solutions.
Here's the description:
Have a program request the user to enter an uppercase letter. Use nested loops to produce a pyramid pattern like this:
A ABA ABCBA ABCDCBA ABCDEDCBA
The pattern should extend to the character entered. For example, the preceding pattern would result from an input value of E .
Hint: Use an outer loop to handle the rows. Use three inner loops in a row, one to handle the spaces, one for printing letters in ascending order, and one for printing letters in descending order.
#include <stdio.h>
int main(void) {
char ch;
char row;
char spaces;
char let;
char back;
printf("Please, insert an uppercase letter: ");
scanf("%c", &ch);
for(row = 'A'; row <= ch; row++) {
for(spaces = ch; spaces > row; spaces--)
printf(" ");
for(let = 'A'; let < row; let++)
printf("%c", let);
for(back = let; back >= 'A'; back--)
printf("%c", back);
printf("\n");
}
return 0;
}