C Program for printing a Pyramid - ASP TANMOY

Latest

Saturday, 26 April 2014

C Program for printing a Pyramid



Write a C program to print a Pyramid




 
Code:


#include<stdio.h>
#include<conio.h>
 int main()
 {
  int n,i,j,sp;
  printf("Enter Number of Rows");
  scanf("%d",&n);
  for(i=1; n>=i; i++)
  {
   for(sp=n-i; sp>=1; sp--)
       printf(" ");
   for(j=i; j>=1; j--)
        printf("*");
   for(j=i; j>1; j--)
        printf("*");
   printf("\n");
  }
  getch();
  return 0;
 }
 
Output:





No comments:

Post a Comment