看起來頗囉唆...
複製程式
#include <stdio.h>
#include <stdlib.h>
int main(void){
int base,i,j,l,r,p,type;
printf("input a odd number:\n");
scanf("%d",&base);
printf("input 1,2,3:\n");
scanf("%d",&type);
printf("-------------------\n");
p=1; //列映
l=(base/2)+1;r=(base/2)+1; //列映範圍
for(i=1;i<=base;i++){ // 共幾列
//printf("l=%d,r=%d",l,r);
for(j=1;j<=base;j++){
if(j>=l&&j<=r){
printf("%d",p);p=(p+2)%10;
}else{
printf(" ");
}
}
printf("\n");
if(type==1){
if(i<(base/2)){l--;r=base/2+1;}
else if(i==(base/2)){l=1;r=base;}
else{l=(base/2)+1;r--;}
}else if(type==2){
if(i<(base/2)){l=(base/2)+1;r++;}
else if(i==(base/2)){l=1;r=base;}
else{l++;r=base/2+1;}
}else{
if(i>(base/2)){l++;r--;}else{l--;r++;}
}
}
}