https://www.hackerrank.com/challenges/printing-pattern-2
Solution
#include <stdio.h>
int main()
{
int n,d,min;
scanf("%d", &n);
d=2*n-1;
for(int i=1;i<=d;i++)
{
for(int j=1;j<=d;j++)
{
if(i<j)
min=i-1;
else
min=j-1;
if(min>d-j)
min=d-j;
if(min>d-i)
min=d-i;
printf("%d ",n-min);
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment