![]() |
The-program-in-C-for-half-pyramid-of-* (star) |
Theory:
Before starting the print of half pyramid of * (star) here are some basics. You should know about for loops as well as nested 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; //Initialization
printf("\nEnter the number of rows: ");
scanf("%d",&k); //Get user input for rows or level
for (i = 1; i <= k; ++i){
for (j = 1; j <= i; ++j){
printf("* "); //Print *(star)
}
printf("\n");
}
return 0;
}
Input:
5
Output:
** ** * ** * * ** * * * *
** ** * ** * * ** * * * *