Friday, 21 July 2017

Write a C program to print circular pattern for a given integer.

Write a C program to print the following pattern for a given integer.
Sample Input 1:
4
Sample Output 1:
4444444
4333334
4322234
4321234
4322234
4333334
4444444

                                       C-Solution
#include<stdio.h>
#include<stdlib.h>
int findmax(int a,int b)
{
    if(a>b)return a;
    else return b;
}
int main()
{
  int n,i,j;
  scanf("%d",&n);
  int m=(n*2)-1;
for(i=0;i<m;i++)
 {
  for(j=0;j<m;j++)
   {
     printf("%d",1+findmax(abs(n-i-1),abs(n-j-1)));
   }printf("\n");
 }
    return 0;
}

No comments:

Post a Comment