## 10.29.2012

### Number Pyramid

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

54321
5432
543
54
5

Ans.

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

The output of above program would be:

 Figure: Screen shot for number pyramid C program

1. @Toki Tahmid Inan,

Your required Number Pyramid Source Code at:

#include"stdio.h"
int main()
{
int num,r,c,n;
printf("Enter Any Number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,n=num; c<=r; c++,n--)
printf("%d", n);
printf("\n");
}
getch();
return 0;
}

1. 5
54
543
5432
54321

1. @Shouvik Das,

Your required number pyramid pattern source code as:

#include"stdio.h"
int main()
{
int num=5,r,c,p;
for(r=1; r<=num; r++)
{
for(c=r,p=num; c>=1; c--,p--)
printf("%d",p);
printf("\n");
}
getch();
return 0;
}

2. By using while loop
54321
5432
543
54
5

1. @ Poojitha Pinninti

Your required number pyramid using while loop source code in C as following:

#include"stdio.h"
#include"conio.h"
int main()
{
int num=5,r,c,p;
r=1;
while(r<=num)
{
p=num;
c=r;
while(c<=num)
{
printf("%d",p);
p--;
c++;
}
r++;
printf("\n");
}

getch();
return 0;
}

3. 1
12
123
1234
12345 ...?

1. @ Milan Joshi

The C program source code for above Number Triangle Pyramid program here:

http://cprogrammingcodes.blogspot.com/2011/09/10design-numbers-tringle-pyramid.html

4. 4
43
432
4321
how to generate the above pattern

1. #Ritu Naha,

Your required number pattern C program source code as:

#include"stdio.h"
int main()
{
int num=4,r,c,p;
for(r=1; r<=num; r++)
{
for(c=r,p=num; c>=1; c--,p--)
printf("%d",p);
printf("\n");
}
getch();
return 0;
}

2. How to code the output below in c using while loop
4321
321
21