![]() |
Program-in-c-for-half-pyramid-of-alphabets |
Practice in C programming for Half Pyramid of Alphabets
Theory:
To print the half pyramid of the alphabet practice some "for loops" and some of nested "if-else" conditions not only for better understanding but also clear the concept of loops and if-else conditions. These kinds of problems help you to develop your brain.
Library functions:
- #include <stdio.h>
- #include <stdlib.h>
Here stdio.h for standard input and output functions.
Datatype:
For pattern, we use some integer type variables for loops.
Character type variable for character inputs.
Input function:
scanf("%c");
Output function:
printf("%c");
Source Code:
//The program in C for Half Pyramid of Alphabets
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j;
char c, alphabet= 'A';
printf("Enter an uppercase character: ");
scanf("%c",&c);
for (i = 1; i <= (c- 'A' + 1); i++){
for (j = 1; j <= i; j++){
printf("%c ",alphabet);
}
alphabet++;
printf("\n");
}
return 0;
}
Input:
F
Output:
AB BC C CD D D DE E E E EF F F F F F
AB BC C CD D D DE E E E EF F F F F F