Tuesday, 4 July 2017

C program to print Equilateral triangle (Pyramid) star pattern



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
/**
 * C program to print equilateral triangle or pyramid star pattern
 */
#include <stdio.h>
int main()
{
    int i, j, n;
    //Reads number of rows to be printed
    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 the pyramid pattern
        for(j=1; j<=(2*i-1); j++)
        {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}


Output
X
_
Enter value of n: 5 
    *
   ***
  *****
 *******
*********

No comments:

Post a Comment