Q. Write a C program to print the following number pyramid as:
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
Ans.
/*c program for number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<r; sp++)
printf(" ");
for(c=r; c<=num; c++)
printf("%d ",c);
printf("\n");
}
return 0;
}
The output of above program would be:
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
Ans.
/*c program for number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<r; sp++)
printf(" ");
for(c=r; c<=num; c++)
printf("%d ",c);
printf("\n");
}
return 0;
}
The output of above program would be:
Figure: Screenshot for number pyramid C program |
i want the output like this..
ReplyDelete123456
1234
12
1
please help
For(i=6;i>=1;i-=2)
Delete{
For(j=1;j<=i;j++)
{
Printf("%d",j);
}
printf("\n");
}