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:
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 |
4
ReplyDelete43
432
4321
@Toki Tahmid Inan,
DeleteYour 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;
}
5
ReplyDelete54
543
5432
54321
@Shouvik Das,
DeleteYour 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;
}
By using while loop
ReplyDelete54321
5432
543
54
5
@ Poojitha Pinninti
DeleteYour 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;
}
1
ReplyDelete12
123
1234
12345 ...?
@ Milan Joshi
DeleteThe C program source code for above Number Triangle Pyramid program here:
http://cprogrammingcodes.blogspot.com/2011/09/10design-numbers-tringle-pyramid.html
4
ReplyDelete43
432
4321
how to generate the above pattern
#Ritu Naha,
DeleteYour 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;
}
How to code the output below in c using while loop
Delete4321
321
21