zoukankan      html  css  js  c++  java
  • 做幻方

     #include<stdio.h>
    #include<math.h>
    #include<string>
    #include<iostream>
    #include <stdlib.h>
    using namespace std;

    int main(void)
    {
    int n,t;
    int num[100][100];
    while(cin>>n){
    if(n==0){
    break;
    }
    if(n%2!=1||n<0||n>30){
    continue;
    }
    t=1;
    for(int x=0;x<n;x++){
    for(int y=0;y<n;y++){
    num[x][y]=0;
    }
    }
    for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    num[((i+1)*(n-1)-i+j)%n][(n/2+i*(n-1)+j)%n]=t;
    t+=1;
    }
    }
    for(int a=0;a<n;a++){
    for(int b=0;b<n;b++){
    printf("%3d",num[a][b]);
    }
    printf(" ");
    }
    printf(" ");
    }
  • 相关阅读:
    python re模块
    python
    python
    Django学习手册
    Django学习手册
    前端
    前端
    Django学习手册
    前端
    Database学习
  • 原文地址:https://www.cnblogs.com/xuwanghu/p/3198249.html
Copyright © 2011-2022 走看看