Q. Write a C program for print the following number triangle:
5
45
345
2345
12345
Ans.
/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,num,n,i;
printf("Enter number of rows : ");
scanf("%d", &num);
n = num;
for(r=1; r<=num; r++,n--)
{
for(i=n; i<=num; i++)
printf("%d", i);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
or
Q. Write a C program for display the following number pyramid:5
45
345
2345
12345
Ans.
/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,num,n,i;
printf("Enter number of rows : ");
scanf("%d", &num);
n = num;
for(r=1; r<=num; r++,n--)
{
for(i=n; i<=num; i++)
printf("%d", i);
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Screen shot for number pyramid C program |
can you please tell me how to print this
ReplyDeletesuppose user enter num is 4 then output should be
10
9 6
8 5 3
7 4 2 1
73
62
Can you elaborate your program. If user enter number is 5, then what should be output?
Delete