Q. Write a C program to print the following number pyramid as:
1234
2341
3412
4123
Ans.
/*c program for number pyramid*/
#include<stdio.h>
int main()
{
int num,n,r,c,t;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r; c<=num; c++)
printf("%d",c);
for(t=1; t<r; t++)
printf("%d",t);
printf("\n");
}
return 0;
}
The output of above program would be:
1234
2341
3412
4123
Ans.
/*c program for number pyramid*/
#include<stdio.h>
int main()
{
int num,n,r,c,t;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=r; c<=num; c++)
printf("%d",c);
for(t=1; t<r; t++)
printf("%d",t);
printf("\n");
}
return 0;
}
The output of above program would be:
Figure: Screen shot for number rectangle C program |
Comments
Post a Comment