Write a C program to print the Given pyramid

Posted by Tushar Bedekar




      1


    1 2  
   1 2 3 
  1 2 3 4 
 1 2 3 4 5
  .
  .
  .
  n

Solution:-#include(stdio.h)                        // note place '<' & '>' in place of '(' & ')'
#include(conio.h)
int main( )
{
int r,c,n,sp;
clrscr( );
printf("Enter the no. of rows u want to print:");
scanf("%d", &n);
for(r=1; r<=n; r++)

for(sp=n; sp>=r; sp--)
printf(" ");                                                 // give one space in betw quotations.
for(c=1; c<=r; c++)
printf("%2d", c);
printf("\n");
}
getch( );
return 0;
}

0 comments:

Post a Comment

back to top