Thursday, 28 May 2015

Displaying Pyramid

//Displaying pyramid
#include<stdio.h>
#include<conio.h>
main()
{
   int i,j,num;
   char str[]="0123456789";
   printf("enter no. uptill u want to print pyramid\n");
   scanf("%d",&num);
   for(i=0;i<num;i++)
   {
       for(j=i;j<num;j++)
         printf(" ");
         
      /* The above for loop is for giving spaces for pyramid shape .
         As it reaches to num the bottom most of pyramid , spaces decreases*/

        for(j=i;j>=0;j--)
          printf("%d",j);
     
 for(j+=2;j<=i;j++)
          printf("%d",j);
         printf("\n");
   }
   
}


No comments:

Post a Comment