In this C program, we will learn how to write a program to print a half pyramid using an asterisk (*).
Here is the code of the program to print a half pyramid using an asterisk (*).
/*C Program to print a half pyramid using asterisk (*) */
#include <stdio.h>
void main() {
int a, b, rows;
printf("Enter the number of rows:\t");
scanf("%d", & rows);
for (a = 1; a <= rows; a++) {
for (b = 1; b <= a; b++) {
printf("* ");
}
printf("\n");
}
}
Enter the number of rows: 5
*
* *
* * *
* * * *
* * * * *
--------------------------------
Process exited after 2.222 seconds with return value 5
Press any key to continue . . .
Comments