Printing a pyramid using asterisks

Program Description

The program draws a pyramid on the console.
The program prompts the user for height and then draws the pyramid of the required height on the terminal.

Program
/******************************************
*
*      Printing a pyramid using asterisks
*
*	   code.cheraus.com
********************************************/




#include<stdio.h>

int main()
{
  int height,i,j;
  printf("\nEnter the height of Pyramid : ");
  scanf("%d",&height);
 
  
  for(i=0;i<height;i++)
  {
    for(j=height-1;j>=0;j--)
    {
      if(j<i)
       printf("*");
      else
       printf(" ");
    }
    printf("*");
    for(j=0;j<i;j++)
    {
      printf("*");
    }
    printf("\n");
  }
}

Output
Enter the height of Pyramid : 2

      *
    ***

Comments
comments powered by Disqus