Sunday 28 February 2016

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:

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

}

No comments:

Post a Comment

Ads Inside Post