Print Rectangle Pattern Program In C
Q. Print the rectangle pattern program in C as following design:
1111111
1222221
1233321
1234321
1233321
1222221
1111111
Ans.
1111111
1222221
1233321
1234321
1233321
1222221
1111111
/* source code for print the rectangle pattern program*/
#include<stdio.h>
int main()
{
int num=4,r,c,m,n,p,q=6;
for(r=1; r<=num; r++,q=q-2)
{
for(c=1; c<=r; c++)
printf("%d", c);
for(p=q; p>=1; p--)
printf("%d", r);
for(c=r-1; c>=1; c--)
printf("%d", c);
printf("\n");
}
for(r=3,m=1; r>=1; r--,m=m+2)
{
for(c=1; c<=r; c++)
printf("%d", c);
for(n=m; n>=1; n--)
printf("%d", r);
for(c=r; c>=1; c--)
printf("%d", c);
printf("\n");
}
getch();
return 0;
}
1111111
1222221
1233321
1234321
1233321
1222221
1111111
Ans.
1111111
1222221
1233321
1234321
1233321
1222221
1111111
Tips/Tricks: Each color group represent a loop in rectangle pattern program as the below source code written.
/* source code for print the rectangle pattern program*/
#include<stdio.h>
int main()
{
int num=4,r,c,m,n,p,q=6;
for(r=1; r<=num; r++,q=q-2)
{
for(c=1; c<=r; c++)
printf("%d", c);
for(p=q; p>=1; p--)
printf("%d", r);
for(c=r-1; c>=1; c--)
printf("%d", c);
printf("\n");
}
for(r=3,m=1; r>=1; r--,m=m+2)
{
for(c=1; c<=r; c++)
printf("%d", c);
for(n=m; n>=1; n--)
printf("%d", r);
for(c=r; c>=1; c--)
printf("%d", c);
printf("\n");
}
getch();
return 0;
}
/**********************************************************
The output of above program would be:
***********************************************************/
I am glad you take pride in what you write. This makes you stand way out from many other writers that push poorly written content.
ReplyDeletelist to string in python
Good artcile, but it would be better if in future you can share more about this subject. Keep posting.
ReplyDeletelist to string in python