9.17.2012

Number Triangle


Q. Write a C program for print the following number triangle:
or
Q. Write a C program for display the following number pyramid:

 9
 898
 78987
 6789876

Ans.

/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,num=9,n,i,j;
 n = num;
 for(r=1; r<=4; r++,n--)
 {
  for(i=n; i<=num; i++)
    printf("%d", i);
  for(j=num-1; j>=n; j--)
    printf("%d", j);
  printf("\n");
 }
 getch();
 return 0;
}


The output of above program would be:

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

No comments:

Post a Comment