Monday, 3 December 2012

Number Rectangle Program

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:


Output of number rectangle C program
Figure: Screen shot for number rectangle C program

No comments:

Post a Comment