Thursday, 26 July 2012

Number pyramid

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


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


Ans.


/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,n=6;
 for(r=1; r<=6; r++)
 {
  for(sp=1; sp<=n; sp++)
     printf(" ");
  for(c=1; c<=r; c++)
  {
     printf("%d",r);
     printf(" ");
  }
  printf("\n");
  n=n-1;
 }
 getch();
 return 0;
}


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


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

No comments:

Post a Comment