Sunday 2 September 2012

Number pyramid

Q. Write a C program to print the following number pyramid.
or
Q. write a C program to print the following number triangle.

123456654321
1234554321
12344321
123321
1221
11

Ans.

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

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

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


Related Programs:

Q. Write a C program to print the following character pyramid.

ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA

No comments:

Post a Comment