Welcome![Sign In][Sign Up]
Location:
Search - 07.10.11

Search list

[Other用c编写的N*N的螺旋矩阵源代码

Description:

/*
实现效果:
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
*/
#include <stdio.h>
#define N 5 //阶数,即N*N的螺旋矩阵

void main()
{
    int i, j, num=1, a[N][N];
    for(i=0; i<=N/2; i++)
    {
        for(j=i; j<N-i; j++) a[i][j]=n++;
        for(j=i+1; j<N-i; j++) a[j][N-i-1]=n++;
        for(j=N-i-2; j>i; j--) a[N-i-1][j]=n++;
        for(j=N-i-1; j>i; j--) a[j][i]=n++;
    }
    for(i=0; i<N; i++)
    {
        for(j=0; j<N; j++)
            printf("%2d ",a[i][j]);
        printf("\n");
    }
}
    

 

不知道叫什么,先叫它“回宫图”吧
年初的时候在贴吧瞎逛,看到了一个程序挺有意思,会输出如下的形状:
01 24 23 22 21 20 19
02 25 40 39 38 37 18
03 26 41 48 47 36 17
04 27 42 49 46 35 16
05 28 43 44 45 34 15
06 29 30 31 32 33 14
07 08 09 10 11 12 13
仔细看这个形状,数字是按顺序往里回旋的,觉得很有创意,可是一看源代码头就大了,
每个编程人都知道看别人的代码是很困难的,尤其像这种不知道思路的,所以也就放下
没管了。
昨天上物理课实在是没心思听,就想起这个程序,想了一节课,果然不负有心人,给弄出来了,这个是增强版的,可以输入1-10中的任意个数,然后生成图形。
先看代码,没有注释,所以不好看的懂。
#include<stdio.h>
main()
{
       int n,m,i,j,t,k=1;
       int a[11][11];
       clrscr();
       do{
       printf("please input a number(1-10):");
       scanf("%d",&n);
       }while(n<1||n>10);
       t=n+1;
       for(m=1;m<=t/2;m++)
         {
           for(i=m;i<=t-m;i++)
             {a[i][m]=k;k++;}
           for(j=m+1;j<=t-m;j++)
             {a[i-1][j]=k;k++;}
           for(i=n-m;i>=m;i--)
             {a[i][j-1]=k;k++;}
           for(j=n-m;j>=m+1;j--)
             {a[i+1][j]=k;k++;}
         }
       for(i=1;i<=n;i++)
         {
           for(j=1;j<=n;j++)
             {
               if(a[i][j]<=9) printf("0%d ",a[i][j]);
               else printf("%d ",a[i][j]);       }
           printf("\n");
         }
       getch();
}
就是这样的。


可以更简洁些:

#include<stdio.h>
main()
{
       int n,m,i,j,t,k=1;
       int a[11][11];
       clrscr();
       do{
       printf("please input a number(1-10):");
       scanf("%d",&n);
       }while(n<1||n>10);
       t=n+1;
       for(m=1;m<=t/2;m++)
         {
           for(i=m;i<=t-m;i++)
             a[i][m]=k++;
           for(j=m+1;j<=t-m;j++)
             a[i-1][j]=k++;
           for(i=n-m;i>=m;i--)
             a[i][j-1]=k++;
           for(j=n-m;j>=m+1;j--)
             a[i+1][j]=k++;
         }
       for(i=1;i<=n;i++)
         {
           for(j=1;j<=n;j++)
             {
               if(a[i][j]<=9) printf("0%d ",a[i][j]);
               else printf("%d ",a[i][j]);       }
           printf("\n");
         }
       getch();
}

 


 #include <stdio.h>
#define N 8
main(){
 int i,j,n=1,a[N][N];
 for(i=0;i<=N/2;i++){
  for(j=i;j<N-i;j++)
   a[i][j]=n++;
  for(j=i+1;j<N-i;j++)
   a[j][N-i-1]=n++;
  for(j=N-i-2;j>i;j--)
   a[N-i-1][j]=n++;
  for(j=N-i-1;j>i;j--)
   a[j][i]=n++;
 }
 for(i=0;i<N;i++){
  printf("\n\n");
  for(j=0;j<N;j++)
   printf("%5d",a[i][j]);
 }
}
 

 


                                马踏棋盘问题


#include <stdio.h>
#define N 5
void main(){
 int x,y;
 void horse(int i,int j);
 printf("Please input start position:");
 scanf("%d%d",&x,&y);
 horse(x-1,y-1);
}
void horse(int i,int j){
 int a[N][N]={0},start=0,
  h[]={1,2,2,1,-1,-2,-2,-1},
  v[]={2,1,-1,-2,2,1,-1,-2},
  save[N*N]={0},posnum=0,ti,tj,count=0;
 int jump(int i,int j,int a[N][N]);
 void outplan(int a[N][N]);
 a[i][j]=posnum+1;
 while(posnum>=0){
  ti=i;tj=j;
  for(start=save[posnum];start<8;++start){
   ti+=h[start];tj+=v[start];
   if(jump(ti,tj,a))
    break;
   ti-=h[start];tj-=v[start];
  }
  if(start<8){
   save[posnum]=start;
   a[ti][tj]=++posnum+1;
   i=ti;j=tj;save[posnum]=0;
   if(posnum==N*N-1){
    //outplan(a);
    count++;
   }
  }
  else{
   a[i][j]=0;
   posnum--;
   i-=h[save[posnum>;j-=v[save[posnum>;
   save[posnum]++;
  }
 }
 printf("%5d",count);
}
int jump(int i,int j,int a[N][N]){
 if(i<N&&i>=0&&j<N&&j>=0&&a[i][j]==0)
  return 1;
 return 0;
}
void outplan(int a[N][N]){
 int i,j;
 for(i=0;i<N;i++){
  for(j=0;j<N;j++)
   printf("%3d",a[i][j]);
  printf("\n");
 }
 printf("\n");
 //getchar();
}
用回溯法得到所有的解,但效率较低,只能算出5行5列的

 


Platform: | Size: 4395 | Author: good@588 | Hits:

[Windows Developfreewebhd0313

Description: 免費分享版網路硬碟 01.創意風格首頁 02.申請會員 03.密碼查詢 04.會員容量限制 05.上傳檔案支援  Persits.Upload Dundas.Upload LyfUpload.UploadFile iNotes.Upload 06.多檔上傳,最多一次10個檔案 07.重新命名 08.刪除檔案、資料夾 09.剪下、複製、貼上 10.上移功能 11.會員列表、會員修改、刪除會員 12.系統資訊列表、系統修改 13.清單模式、縮圖模式  支援線上縮圖,Persits.Jpeg  ASPThumb 14.Persits.Upload Dundas.Upload支援上傳BAR進度顯示功能 15.Admin可觀看  使用者在線顯示、目前位址 16.WebHD總使用容量統計 17.會員使用容量統計 18.Admin新增會員功能 本程式適用於:   Windows  2003,Windwos  xp,Windows  2000 使用限制:   須先至本站註冊取得啟用資料庫,才可使用本系統!(註冊完全免費)   無法修改首頁圖片、廣告視窗於下方   須先安裝   Scripting.FileSystemObject ADODB.Connection   才可使用 系統管理員預設值:   帳號:Admin   密碼:system -free sharing network hard disk version 01. Page 02 creative style. Apply for membership 03. Password inquiries 04. Will 05 Members of the capacity constraints. Upload File Support
Platform: | Size: 193465 | Author: ka kit | Hits:

[SourceCodeRound.c

Description: 01.//cnsGLArc.cpp : Defines the entry point for the console application. 02. 03. 04. 05.//Filename:cnsGLArc.cpp 06. 07.//Function:Draw arc by Bresenham 08. 09.//Author:9Cat 10. 11.//OS:WindowsXP Sp2 12. 13.//Development Tool:Visual C++ 2005 14. 15.//Other refrence:OpenGL 16. 17.//First Create Time:2008-07-13 18:37 18. 19.//Last Modify Time:2008-07-13 22:38
Platform: | Size: 2699 | Author: dragonye_2007 | Hits:

[Embeded-SCM Developfreewebhd0313

Description: 免費分享版網路硬碟 01.創意風格首頁 02.申請會員 03.密碼查詢 04.會員容量限制 05.上傳檔案支援  Persits.Upload Dundas.Upload LyfUpload.UploadFile iNotes.Upload 06.多檔上傳,最多一次10個檔案 07.重新命名 08.刪除檔案、資料夾 09.剪下、複製、貼上 10.上移功能 11.會員列表、會員修改、刪除會員 12.系統資訊列表、系統修改 13.清單模式、縮圖模式  支援線上縮圖,Persits.Jpeg  ASPThumb 14.Persits.Upload Dundas.Upload支援上傳BAR進度顯示功能 15.Admin可觀看  使用者在線顯示、目前位址 16.WebHD總使用容量統計 17.會員使用容量統計 18.Admin新增會員功能 本程式適用於:   Windows  2003,Windwos  xp,Windows  2000 使用限制:   須先至本站註冊取得啟用資料庫,才可使用本系統!(註冊完全免費)   無法修改首頁圖片、廣告視窗於下方   須先安裝   Scripting.FileSystemObject ADODB.Connection   才可使用 系統管理員預設值:   帳號:Admin   密碼:system -free sharing network hard disk version 01. Page 02 creative style. Apply for membership 03. Password inquiries 04. Will 05 Members of the capacity constraints. Upload File Support
Platform: | Size: 193536 | Author: ka kit | Hits:

[DSP programlot-of-good-DSP-experimental-program

Description: 经典的DSP试验程序集合! 01指令实验 02存储器 03串行口 04同步串口 05步进电机 06硬件中断 07定时器 08交通灯 09直流电机 10滤波器 11正弦波发生器 12语音录放 13显示屏-DSP testing procedures classic collection! 01 Directive 03 Experiment 02 ROM 04 synchronous serial port serial port 05 stepper motor 06 hardware interrupt 07 timer 08 traffic lights 09 DC 10 filter 11 sine wave generator 13, display 12, voice recording
Platform: | Size: 64512 | Author: 江可乐 | Hits:

[JSPJavascript.chm

Description: Java script脚本常用代码(全)2007-07-11 13:48click() 对象.click() 使对象被点击 closed 对象.closed 对象窗口是否已关闭true/false clearTimeout(对象) 清除已设置的setTimeout对象 clearInterval(对象) 清除已设置的setInterval对象 confirm("提示信息") 弹出确认框,确定返回true取消返回false -Commonly used Java script script code (all) 2007-07-11 13:48 click () object. Click () so that the object is clicked closed object. Closed the target window has been shut down true/false clearTimeout (object) has been set up to clear setTimeout Object clearInterval (object) has been set up to clear the setInterval object confirm (
Platform: | Size: 4096 | Author: 冯维星 | Hits:

[GUI Develop07

Description: 第7章操作系统与Windows相关程序 7.1 启动相关 7.2 获得磁盘属性 7.3 磁盘相关设置 7.4 系统控制 7.5 系统设置 7.6 系统监控 7.7 系统软件信息 7.8 鼠标操作 7.9 程序控制 7.10 程序运行 7.11 系统隐藏 7.12 其他 -Chapter 7 and the Windows operating system related procedures related to 7.2 to obtain 7.1 startup disk 7.3 disk related property settings 7.4 System Control 7.5 System Settings 7.6 System Monitor 7.7 System Software 7.9 information 7.8 mouse control system 7.10 program runs hidden 7.12 Other 7.11
Platform: | Size: 993280 | Author: cp | Hits:

[Special Effects07.10.11

Description: 图像增强的ppt,做毕业设计时参考的东西-Digital Image Processing;Image enhancement
Platform: | Size: 1005568 | Author: shenme | Hits:

[Com Portmux

Description: 手机多串口编程的资料: 多串口协议GSM0710的各种文档以及参考代码。 0. Readme.txt 本文档 1. 710MUX 源代码,微软MUX驱动模板 2. E901Mux 源代码,E901手机实际运行的MUX驱动 3. mux 一款参考源代码 4. 3GPP-0710.doc 3GPP的多串口协议文档 5. GSM0710_Version7.0.0.pdf GSM07.10 协议规范(英文) 6. GSM0710中文版.doc 本人对GSM0710_Version7.0.0.pdf的翻译 7. NXP_MuTa_SyUM.pdf NXP对MUX部分的介绍(Part2 and Part3 ) 8. gsm0710.c 一份参考源代码 9. gsm0710.jpg 协议的简要流程图 10. gsm0710总结.txt 简单的总结 11. request.dat 请求的数据原样 12. request.txt 对请求数据的分析 13. reply.dat 响应的数据原样 14. reply.txt 对响应数据的分析-mux GSM0710 doc and source code.
Platform: | Size: 1587200 | Author: Hill | Hits:

[JSP/JavajsGraphicsDemo2010.11.17.22.07

Description: 矢量图形编辑系统基于一个javaScript库JSDRAW2D,该库中封装了绘制各种图元的函数。提供了设置图元的基本属性的类库。该类库采用纯javaScript和DOM语言编写。以一个像素的DIV作为矢量图形的最小单位,所以绘制出来的图形具有速度快,占用空间小的优势。 矢量图形编辑系统,采用动态绘制,选择所需的图形按钮,在绘图区,随着鼠标拖动,同代绘制图形。同时该系统采用AJAX技术,将绘制好的图形的基本属性,传入服务器中,保存到图形数据库中。 -Vector graphics editing system based on a javaScript library JSDRAW2D, the library encapsulates a function to draw various primitives. Provides a set of basic properties of primitive library. The library and the pure javaScript DOM language. DIV as a pixel the smallest unit vector graphics, so draw out the graph has the speed, small footprint advantages. Vector graphics editing systems, dynamic rendering, select the graphic button in the drawing area, with the mouse to drag, draw the graphics the same generation. Meanwhile, the system uses AJAX technology to draw the basic attributes of good graphics, incoming server, saved to the graphics database.
Platform: | Size: 11365376 | Author: liyu | Hits:

[MiddleWareVHDL-Keyboard

Description: 设计制作一个检测4*4矩阵键盘的按键编码的实验,把实际按键的键值的八位编码先转换成从0000—1111的编码,再译成数码管能识别的八位编码,在数码管动态显示时,4*4矩阵键盘的第一行对应00—03,第二行对应04—07,第三行08—11,第四行对应12—15。-Design a 4* 4 matrix keyboard key coding experiments to detect the key the actual key octet coded first convert from 0000-1111 encoding, and then translated into digital tube to identify the eight coding, digital tube dynamic display, the first line of the 4* 4 matrix keyboard corresponding to 00-03, the second line corresponds to 04-07, the third line of 08-11, the fourth line corresponds to 12-15.
Platform: | Size: 15360 | Author: zj | Hits:

[matlabShop-scheduling--ga_jsp

Description: 用遗传算法解决车间调度问题 aberrance.m 760 24-07-07|09:42 across.m 2144 26-07-07|16:35 cal.m 1133 20-05-08|08:37 calP.m 742 15-05-08|20:16 caltime.m 1986 25-07-07|10:52 JSP.m 4006 22-05-08|19:52 plotRec.m 487 14-07-07|14:48 车间调度遗传算法的研究.doc 87552 26-07-07|15:51 ga_jsp 0 30-12-08|16:-The genetic algorithm to solve the job shop scheduling problem aberrance.m 760 24-07-07 | 09:42 across.m 2144 26-07-07 | 16:35 cal.m 1133 20-05-08 | 08:37 calP.m 742 15-05-08 | 20:16 caltime.m 1986 25-07-07 | 10:52 JSP.m 4006 22-05-08 | 19:52 plotRec.m 487 14-07-07 | 14:48 shop scheduling the study of the genetic algorithm. doc 87552 26-07-07 | 15:51 ga_jsp 0 30-12-08 | 16:33
Platform: | Size: 51200 | Author: 寂寞孤鸿 | Hits:

[CSharpPhaseDerivativeVariance_r1

Description: 基于matlab实现干涉显微镜图像重构的相位质量优质度计算函数- PhaseDerivativeVariance creates a phase quality map by computing the variance of the partial derivatives of the locally unwrapped phase. This is then used to guide the phase unwrapping path. Uses only the 4 nearest neighbours. The user may also input a binary mask. function derivative_variance = PhaseDerivativeVariance (IM_phase, varargin) Created by BS Spottiswoode on 18/10/2004 Last modified on 06/12/2004 2010/07/19 Carey smith Corrected a bug on the line before computing dy (dimx, :)
Platform: | Size: 1024 | Author: zhouxin | Hits:

[Software Engineering11-07-11

Description: AD9910实现脉冲内线性调频信号,仅供参考-AD9910 to achieve linear FM pulse signal, for reference only
Platform: | Size: 470016 | Author: pick | Hits:

[VHDL-FPGA-Verilog098111__1367421625730

Description:  DE2_System_v1.4a.zip   71.2M  2007- 02 22:51  For DE2 boards with Serial Number (S/N) starting with Digit 0 and QuartusII version 6.0   DE2_System_v1.4b.zip   79.4M  2007-07-11 22:42  For DE2 boards with Serial Number (S/N) starting with Digit 0 and QuartusII version 7.1   DE2_System_v1.5.zip   70.5M  2007-07-02 22:52  For DE2 boards with Serial Number (S/N) starting with Digit 0 and QuartusII version 6.0   DE2_System_v1.6.zip   79.2M  2007-11-21 07:33  For DE2 boards with Serial Number (S/N) starting with Digit 1 and QuartusII version 7.1  - DE2_System_v1.4a.zip   71.2M  2007-07-02 22:51  For DE2 boards with Serial Number (S/N) starting with Digit 0 and QuartusII version 6.0   DE2_System_v1.4b.zip   79.4M  2007-07-11 22:42  For DE2 boards with Serial Number (S/N) starting with Digit 0 and QuartusII version 7.1   DE2_System_v1.5.zip   70.5M  2007-07-02 22:52  For DE2 boards with Serial Number (S/N) starting with Digit 0 and QuartusII version 6.0   DE2_System_v1.6.zip   79.2M  2007-11-21 07:33  For DE2 boards with Serial Number (S/N) starting with Digit 1 and QuartusII version 7.1  
Platform: | Size: 527360 | Author: | Hits:

[OtherGWAHWAHWAH2010-07-11

Description: 易语言 非常不错的源码|!! !! ~-Easy language very good source |! ~
Platform: | Size: 34816 | Author: kongbai | Hits:

[Otherkav2015_2015-07-11

Description: 尽量不要让站长把时间都花费在为您修正说明上。压缩包解压时不能有密码。-this a matlab
Platform: | Size: 3072 | Author: zhaoyong | Hits:

[Crack HackElement-3D-V2.0.7-hanhua

Description: E3D2.07汉化Speaking Chinese-E3d Speaking Chinese
Platform: | Size: 2663424 | Author: 于涵 | Hits:

[IOSwxzdhyx

Description: 功能列表如下 01.导入手机号码到通讯录和添加新好友 02.裙发助手裙发好友 03.自动附近人打招呼 04.朋友圈自动点赞评论 05.自动发朋友圈 06.添加通讯录好友 07.添加手机号码好友 08.添加QQ号码好友 09.裙发通讯录(带删除僵尸粉) 10.删除僵尸粉 11.漂流瓶 12.修改资料 13.关注公众号 14.转发好友文章到朋友圈 15.站街扫街(需要定位软件) 16.扫二维码加群 17.清理存储空间 18.批量自动登陆 19.扫描电脑上的二维码登陆电脑躲开 21.分批裙发 22.微群裙发 23.好友裙发 24.加群好友 25.摇一摇 26.附近的人 27.一键点赞 28.朋友圈一键转发(包括小视频) 29.删除僵尸粉 30.最近联系人 31.清空缓存- Píngguǒ bǎn wēixìn zìdònghuà yíngxiāo Apple version of WeChat automation marketing
Platform: | Size: 32768 | Author: 张恒 | Hits:

[Communication-MobileSerialCommunication1.18

Description: 打开串口通讯成功后, 实时监控区将显示实的温湿度值、 光照度值、经纬和温湿曲线。坐标范围可以手动输入,也可以使用默认值。 //通信协议 说明 包头 长度 设备类型 网络号 短地址 命令 数据 校验和 长度 2 2 2 2 2 1 1 位置 0 2 4 6 8 10 11 len - 1 1.温湿度上传数据命令 AA BB 0F 00 F4 01 D0 07 62 53 1E 14 3B 00 62(After the serial port communication is successful, the real time monitoring area will show the real temperature and humidity value, the illumination value, the warp and the latitude and the temperature and humidity curves. The coordinate range can be manually entered, and the default values can be used. 1. temperature and humidity uploading data command AA BB 0F 00 F4 01 D0 076253 1E 14 3B 0062)
Platform: | Size: 14020608 | Author: 仰望星空11 | Hits:
« 12 3 4 5 »

CodeBus www.codebus.net