Q. Write a C program to print the following number rectangle design :
12321
12 21
1 1
12 21
12321
Ans.
/*c program for number rectangle design*/
#include<stdio.h>
int main()
{
int num,n,r,c,sp,q,t;
printf("Enter any number : ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=2; c++)
{
if(r==3)
{
printf("1 ");
break;
}
else
printf("%d",c);
}
for(sp=r; sp>1; sp--)
printf(" ");
for(t=n; t>=1; t--)
printf("%d",t);
printf("\n");
}
for(r=1; r<=num-1; r++)
{
for(c=1; c<=2; c++)
printf("%d",c);
for(sp=r; sp<=1; sp++)
printf(" ");
for(t=r+1; t>=1; t--)
printf("%d",t);
printf("\n");
}
return 0;
}
The output of above program would be:
12321
12 21
1 1
12 21
12321
Ans.
/*c program for number rectangle design*/
#include<stdio.h>
int main()
{
int num,n,r,c,sp,q,t;
printf("Enter any number : ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=2; c++)
{
if(r==3)
{
printf("1 ");
break;
}
else
printf("%d",c);
}
for(sp=r; sp>1; sp--)
printf(" ");
for(t=n; t>=1; t--)
printf("%d",t);
printf("\n");
}
for(r=1; r<=num-1; r++)
{
for(c=1; c<=2; c++)
printf("%d",c);
for(sp=r; sp<=1; sp++)
printf(" ");
for(t=r+1; t>=1; 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