⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 第六章实验二(1)魔方阵.c

📁 第六章实验二(1)本程序为魔方阵.C 可用来求出所指定大小的魔方
💻 C
字号:
/* 第六章实验二求魔方阵,由于屏幕有限本程序允许最大阶数为15----Author:zhg_2006.5.13
*/
#include<stdio.h>
void Dole_Rob(int N);
void zhg_information(char Date[]);
void main()
{
  int N;   
  char panduan,date[]={"May 13th,2006"};
  while(1==1)      // 因条件在循环体中故并不能形成无限循环
  {
    zhg_information(date);
    printf("\n\n\n\n   Please input an odd number N(<=15):   ");
    scanf("%d",&N);   
    while(N%2==0||N<3||N>15)
    {
      zhg_information(date);
      printf("\n\n\n\n\t\t\t\t Input Error !\n\n\n\n\tPlease continue:   ");
      scanf("%d",&N);
    }
    zhg_information(date);
    printf("\n\n\n\n    The result:\n\n");
    Dole_Rob(N);
    printf("\n\n   To exit press the key 0.\t\tTo continue press anyothers.");
    panduan=getch();
    if(panduan=='0')
      break;
  }
  over:putchar('\a');
}
void Dole_Rob(int N)
{
  int array[17][17],i,j,k;       // 用17而非15是为了保险
  for(i=0,j=N/2,k=1;k<=N*N;k++)
  {
    array[i][j]=k;
    {
      if(array[i][j]%N==0)	// 此条件比下面两条件的“优先级”高
      { 
        i++;	
	continue;
      }
      if(i==0)
      {
        i=N-1;
	j++;
	continue;
      }
      if(j==N-1)
      {
        i--;
	j=0;
	continue;
      }
    }
    i--;
    j++;

  }
  for(i=0;i<=N-1;i++)
  {
    printf("      ");
    for(j=0;j<=N-1;j++)
      printf("%3d  ",array[i][j]);
    putchar('\n');
  }
}
#include<stdio.h>
#include<conio.h>
void zhg_information(char Date[])       
{
  clrscr();
  printf("\n\t\t\t   All  Rights  Reserved !!!\n");
  printf(" Wuhan University\t\t\t\t\t\t----Author: zhg\n");
  printf(" E-mail: wudazhg@163.com%55s\n\n",Date);
}






⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -