Problem
Write a program in C to print Half pyramid using * as shown.
*
* *
* * *
* * * *
* * * * *
How to create and display Half Pyramid pattern in C ?
#include <stdio.h> int main() { int index1, index2, n; printf("Abundantcode.com Coding samples\n"); printf("Enter the total number of rows: "); scanf("%d",&n); for(index1=1; index1<=n; ++index1) { for(index2=1; index2<=index1; ++index2) { printf("* "); } printf("\n"); } return 0; }
Output
Abundantcode.com Coding samples
Enter the total number of rows: 5
*
* *
* * *
* * * *
* * * * *
Leave a Reply