Alphabet Pattern Program in C Using For Loop

Alphabet Pattern Program in C Using For Loop for beginners to print the alphabet pyramid pattern using for loop in uppercase and lower case in c program

For Loop in C

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times. The loop allows us to do an arbitrary number of steps in a single line. A loop is a programming structure in computer science that repeats a sequence of instructions until a certain condition is met. The while loop and the for loop are two of the most common loop types.

Pre Increment in For Loop

So, while there is no difference for simple objects, pre increment should be used for iterators and other template objects. Because you use simple type, there are no side effects, and post- or pre increments are run after the loop body, there is no impact on the value in the loop body.

#include <stdio.h>
int main()
{
int i, j;
char input, alphabet = 'A';
printf("Enter a letter");
scanf("%c", &input);
for (i = 1; i <= (input - 'A' + 1); ++i) 
{
for (j = 1; j <= i; ++j) 
{
printf("%c ", alphabet);
}
++alphabet;
printf("\n");
}
return 0;
}

Output:

Enter a letter G
A
B B
C C C
D D D D
E E E E E
F F F F F F
G G G G G G G