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