Q. Write a C program to print the following number rectangle:
1333
2222
3331
Ans.
/*c program for print number rectangle pyramid*/
#include<stdio.h>
int main()
{
int num,n,r,c,k;
printf("Enter no. of rows: ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=r; c++)
printf("%d",r);
for(k=1; k<=n; k++)
printf("%d",n);
printf("\n");
}
return 0;
}
The output of above program would be:
1333
2222
3331
Ans.
/*c program for print number rectangle pyramid*/
#include<stdio.h>
int main()
{
int num,n,r,c,k;
printf("Enter no. of rows: ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=1; c<=r; c++)
printf("%d",r);
for(k=1; k<=n; k++)
printf("%d",n);
printf("\n");
}
return 0;
}
The output of above program would be:
Figure: Screen shot for number rectangle pyramid C program |
No comments:
Post a Comment