one method
#include<stdio.h>
#define min(x,y)
(x<y?x:y)
int main() {
int n,i,j,r;
scanf("%d",&n);
r=2*n-1;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
int x=(i<n?i:(r-i-1));
int y=(j<n?j:(r-j-1));
printf("%d",n-min(x,y));
}
printf("\n");
}
}
second method
#include<stdio.h>
int main()
{
int i, j, n;
scanf("%d",&n);
for(i=n; i>=1; i--)
{
for(j=n;j>i;j--)
{
printf("%d", j);
}
for(j=1;j<=(2*i-1);j++)
{
printf("%d", i);
}
for(j=i+1; j<=n; j++)
{
printf("%d", j);
}
printf("\n");
}
for(i=1; i<n; i++)
{
for(j=n; j>i; j--)
{
printf("%d", j);
}
for(j=1; j<=(i*2-1); j++)
{
printf("%d", i+1);
}
for(j=i+1; j<=n; j++)
{
printf("%d", j);
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment