Pyramid - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Wednesday 8 November 2017

Pyramid

/*
     *
    ***
   *****
  *******
 *********
*/

#include <stdio.h>

int main()
{

    int row, c, n, temp;

    printf("Enter the number of rows in pyramid of stars you wish to see ");
    scanf("%d", &n);

    temp = n;

    for (row = 1; row <= n; row++)
    {

        for (c = 1; c < temp; c++)
            printf(" ");

        temp--;

        for (c = 1; c <= 2 * row - 1; c++)
            printf("*");

        printf("\n");

    }

    return 0;
}
OUTPUT
Enter the number of rows in pyramid of stars you wish to see 7
      *
     ***
    *****
   *******
  *********
 ***********
*************

No comments:

Post a Comment

Post Top Ad