关于C语言的数字漩涡形输出: 1 16 15 14 13 2 17 24 23 12 3 18 25 22 11 4 19 20 21 10 5 6 7 8 9
1个回答
展开全部
#include<stdio.h>
int main()
{
int i,j,k,n,a[100][100],b[2],t,x,y;
n=5;
b[0]=0;
b[1]=1;
k=n;
t=1;
x=1;
while(x<=n*n)
{
for(y=1;y<=2*k-1;y++)
{
b[y/(k+1)]=b[y/(k+1)]+t;
a[b[0]][b[1]]=x;
x=x+1;
}
k=k-1;
t=-t;
}
for(i=1;i<=n;i++)
{
//printf("\n");
for(j=1;j<=n;j++)
printf("%3d",a[i][j]);
printf("\n");
}
getch();
}
int main()
{
int i,j,k,n,a[100][100],b[2],t,x,y;
n=5;
b[0]=0;
b[1]=1;
k=n;
t=1;
x=1;
while(x<=n*n)
{
for(y=1;y<=2*k-1;y++)
{
b[y/(k+1)]=b[y/(k+1)]+t;
a[b[0]][b[1]]=x;
x=x+1;
}
k=k-1;
t=-t;
}
for(i=1;i<=n;i++)
{
//printf("\n");
for(j=1;j<=n;j++)
printf("%3d",a[i][j]);
printf("\n");
}
getch();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询