4.18.2015

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

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:
***********************************************************/

Output of Print Rectangle Pattern Program In C
Figure: Screen shot for Print Rectangle Pattern Program In C

You might also like:

  1. Big list of 98+ C Pattern Programs
  2. Latest Pattern Program list asked by user

No comments:

Post a Comment