C programs to print the half pyramid pattern have been given here. Both the right half and left half of the pyramid using *, numbers and letters have been covered.
Page content(s):
1. Program & Output: Right half pyramid
2. Program & Output: Left half pyramid
3. Program & Output: Inverted half pyramid
1. Program & output to print the right half pyramid pattern
1.1. C Program & output to print the right half pyramid pattern using *
/***************************** alphabetacoder.com C program to print the right half pyramid pattern using * ******************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print * for (j = 1; j <= i; j++) { printf("*"); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
*
**
***
****
*****
******
1.2. C Program & output to print the right half pyramid pattern using numbers
/********************************* alphabetacoder.com C program to print the right half pyramid pattern using numbers **********************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print numbers for (j = 1; j <= i; j++) { printf("%d ", j); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1.3. C Program & output to print the right half pyramid pattern using alphabets
/*********************************** alphabetacoder.com C program to print the right half pyramid pattern using alphabets ************************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print letters for (j = 1; j <= i; j++) { printf("%c ", j + 64); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
A
A B
A B C
A B C D
A B C D E
A B C D E F
2. Program & output to print the left half pyramid pattern
2.1. C Program & output to print the left half pyramid pattern using *
/******************************** alphabetacoder.com C program to print the left half of the pyramid pattern using * *********************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print space for (j = 1; j <= row - i; j++) { printf(" "); } // print * for (j = 1; j <= i; j++) { printf("*"); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
*
**
***
****
*****
******
2.2. C Program & output to print the left half pyramid pattern using numbers
/*********************************** alphabetacoder.com C program to print the left half of the pyramid pattern using numbers ************************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print space for (j = 1; j <= 2 * (row - i); j++) { printf(" "); } // print numbers for (j = 1; j <= i; j++) { printf("%d ", j); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
2.3. C Program & output to print the left half pyramid pattern using alphabets
/************************************* alphabetacoder.com C program to print the left half of the pyramid pattern using alphabets **************************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print space for (j = 1; j <= 2 * (row - i); j++) { printf(" "); } // print letters for (j = 1; j <= i; j++) { printf("%c ", j + 64); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 5
A
A B
A B C
A B C D
A B C D E
3. Program & output to print the right half pyramid pattern
3.1. C Program & output to print the inverted half pyramid pattern using *
/****************************** alphabetacoder.com C program to print the inverted half pyramid pattern using * *******************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print * for (j = row; j >= i; j--) { printf("*"); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
******
*****
****
***
**
*
3.2. C Program & output to print the inverted half pyramid pattern using numbers
/********************************* alphabetacoder.com C program to print the inverted half pyramid pattern using numbers **********************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print numbers for (j = row; j >= i; j--) { printf("%d ", (row - j + 1)); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
3.3. C Program & output to print the inverted half pyramid pattern using alphabets
/*********************************** alphabetacoder.com C program to print the inverted half pyramid pattern using alphabets ************************************/ #include <stdio.h> int main() { // declare variables int row, i, j; // take input printf("Enter the number of rows: "); scanf("%d", & row); // new line printf("\n"); // display the pattern for (i = 1; i <= row; i++) { // print letters for (j = row; j >= i; j--) { printf("%c ", (row - j + 65)); } // new line printf("\n"); } return 0; }
Output
Enter the number of rows: 6
A B C D E F
A B C D E
A B C D
A B C
A B
A