Program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| /** * C program to print hollow pyramid or hollow equilateral triangle star pattern */#include <stdio.h>int main(){ int i, j, n; //Reads number of rows to be printed from user printf("Enter value of n : "); scanf("%d", &n); for(i=1; i<=n; i++) { //Prints trailing spaces for(j=i; j<n; j++) { printf(" "); } //Prints hollow pyramid for(j=1; j<=(2*i-1); j++) { if(i==n || j==1 || j==(2*i-1)) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0;} |
Output
Enter value of n: 5
*
* *
* *
* *
*********
*
* *
* *
* *
*********
No comments:
Post a Comment