Q. Write a C program to print the following number pyramid:
54321
4321
321
21
1
Ans.
/*c program code for number triangle*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
for(r=1; r<=5; r++,num--)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=num; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*********Output**********/
54321
4321
321
21
1
Ans.
/*c program code for number triangle*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
for(r=1; r<=5; r++,num--)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=num; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/*********Output**********/
Screen shot for number triangle |
sir how can we do this
ReplyDelete54321
*5432
**543
***54
****5
54321
ReplyDelete321
21
1
give me the code for above problem
my whatsapp number is 09997186023
fardeen