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 |
Comments
Post a Comment