![]() |
Program-in-c-for-half-pyramid-of-number |
Theory:
To print the half pyramid of numbers practice some "for loops" and some of nested "if-else" conditions for better understanding.
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.
Input function:
scanf(" ");
Output function:
printf(" ");
Source Code:
//The program in C for Half Pyramid of *
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, j, k;
printf("Enter the number of rows: ");
scanf("%d",&k);
for (i = 1; i <= k; ++i) {
for (j = 1; j <= i; ++j) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
Input:
5
Output:
11 21 2 31 2 3 41 2 3 4 5
11 21 2 31 2 3 41 2 3 4 5