INNER REDUCING PATTERN
Consider the following I/O samples.
SAMPLE INPUT: 4
SAMPLE INPUT: 4 4 4 4 4 4 4
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4
C PROGRAM:
#include <stdio.h>
int min(int m,int n,int o,int p);
int min(int m,int n,int o,int p)
{
int min1=m>n?n:m;
int min2=o>p?p:o;
return min1>min2?min2:min1;
}
int main()
{
int n,i,j,x;
scanf("%d",&n);
for(i=0;i<(n*2)-1;i++,printf("\n"))
{
for(j=0;j<(n*2)-1;j++)
{
x=(min(i,j,((n*2-2)-i),((n*2-2)-j)));
printf("%d ",(n-x));
}
}
return 0;
}
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment