Pages

Saturday, April 5, 2014

Number pyramid

Q. Write a C program to print the following number structure:


          1
         1 2
        1 2 3
       1 2 3 4
      1 2 3 4 5 
     1 2 3 4 5 6


Ans.


/*c program to print the above number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,num;
 printf("Enter loop repeat number(rows): ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
   for(sp=num; sp>=r; sp--)
      printf(" ");
   for(c=1; c<=r; c++)
      printf(" %d", c);
   printf("
"
);

 }
 getch();
 return 0;
}


/************Output************/


Output of C program for number pyramid C program
Screen shot for number pyramid C program

Related Posts by Categories

0 comments:

Post a Comment