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

📄 ch26-7.c

📁 C语言程序设计上机指导与练习 冶金工业出版社 刘怀亮
💻 C
字号:
#include<stdio.h> 
#include<conio.h> 
#define Max 15 
void main() 
{ 
   int i,row,col,odd; 
   int m[Max][Max]; 
   printf("\nPlease input an odd:"); 
   scanf("%d",&odd); 
   if(odd<=0||odd%2==0) 
   { 
      printf("\nInput Error!\n"); 
      getch(); 
   } 
   printf("\nodd=%d\n\n",odd); 
   row=0; 
   col=odd/2; /*1 placed in the middle of the first row */
   for(i=1;i<=odd*odd;i++) 
   { 
      m[row][col]=i; 
      if(i%odd==0) /*to the last col*/ 
         if(row==odd-1) /*to the last row*/ 
            row=0; 
         else 
            row++; 
      else /*outmost else*/ 
      { 
         if(row==0) 
            row=odd-1; 
         else 
            row--; 
         if(col==odd-1) 
            col=0; 
         else 
            col++; 
      } /*end of outmost else*/ 
   } /*end of for*/ 
   for(row=0;row<odd;row++) 
   { 
      for(col=0;col<odd;col++) 
         printf("%4d",m[row][col]); 
      printf("\n\n");
   } 
   getch(); 
} 

⌨️ 快捷键说明

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