Welcome![Sign In][Sign Up]
Location:
Search - 06.d

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:

[ICQ-IM-Chatjabberd-2.0s11.tar

Description: jabber jabberTest.rar - Id: pasvlogin.c,v 1.10 2003/02/16 04:18:47 dpuryear Exp $ * * Just logon n users. Do not send any message traffic (2006-04-03,C-C++,45KB,6次) miranda-im-v0.4src.zip - 基于windows API的即时通讯软件,采用jabber开放协议,可以和msn qq等互通 (2005-06-29,C-C++,2119KB,48次)-jabber jabberTest.rar - Id : pasvlogin.c, v 1.10 2003/02/16 04:18 : 47 dpuryear Exp $ * * n Just logon users. Do not Nicht d any message traffic (2006-04-03, C-C, 45KB. 6) miranda-im-v0.4src.zip-based on the windows API that When communications software, used jabber open agreement, and can exchange such as msn qq (2005-06-29, C-C, 2119KB, 48)
Platform: | Size: 777466 | Author: tom | Hits:

[ELanguageLL(1)yufafenxi

Description: *--- --- --声明--- --- -----*/ /* VC6.0下运行通过 此程序为本人苦心所做,请您在阅读的时候,尊重本人的 劳动。可以修改,但当做的每一处矫正或改进时,请将改进 方案,及修改部分发给本人 (修改部分请注名明:修改字样) Email: jink2005@sina.com QQ: 272576320 ——初稿完成:06-5-27 jink2005 补充: 程序存在问题: (1) follow集不能处理:U->xVyVz的情况 (2) 因本人偷懒,本程序为加入文法判断,故 输入的文法必须为LL(1)文法 (3) 您可以帮忙扩充:消除左递归,提取公因子等函数 (4) …… */ /*-----------------------------------------------*/ /*参考书《计算机编译原理——编译程序构造实践》 LL(1)语法分析,例1: ERTWF# +*()i# 文法G[E]:(按此格式输入) 1 E -> TR 2 R -> +TR 3 R -> 4 T -> FW 5 W -> * FW 6 W -> 7 F -> (E) 8 F -> i 分析例句:i*(i)# , i+i# 例2: 编译书5.6例题1 SHMA# adbe# S->aH H->aMd H->d M->Ab M-> A->aM A->e 分析例句:aaabd# */
Platform: | Size: 5280 | Author: 林月忠 | Hits:

[Menu controlbxcode

Description: VB是用API和图片做的漂亮菜0 character*1 a(30)*40,b*5,c,d,e,f,g 01 A(01)= character*1 a(30)*40,b*5,c,d,e,f,g 02 A(02)= c=char(65) 03 A(03)= d=char(40) 04 A(04)= e=char(41) 05 A(05)= f=char(61) 06 A(06)= g=char(39) 07 A(07)= h=char(13) 08 A(08)= o=char(10) 09 A(09)= do 50 k=48,90 10 A(10)= b(1:1)=char(k) 11 A(11)= b(2:2)=char(46) 12 A(12)= b(3:3)=char(102) 13 A(13)= b(4:4)=char(111) 单!-VB API is done and pictures of nice vegetables 0 1 a character * (30) * 40, * 5 b, c, d, e, f, g 01 A (01) = 1 a character * (30) 40 *, b * 5, c, d, e, f, g 02 A (02) = c = char (65) 03 A (03) = d = char (40) 04 A (04) = e = char (41) 05 A ( 05) = f = char (61) 06 A (06) = g = char (39) 07 A (07) = h = char (13) 08 A (08) = o = char (10) 09 A (09) do = 50 k = 48.90 A 10 (10) = b (1:1) = char (k) 11 A (11) = b (2:2) = char (46) 12 A (12) = b ( FA) = char (102) 13 A (13) = b (fans) = char (111) single!
Platform: | Size: 2644 | Author: dfd | Hits:

[JSP/Javapppp123

Description: java ejb开发 程序4、语句alter table people add(phone_number varchar2(10)) 的作用是 A 修改表结构 B 为people表添加约束,约束名称是phone_number C 向people表中添加一列,名称是phone_number,数据类型是varchar2,长度是10 D 上述答案均不正确 5、( )BLOB和CLOB的区别在于 A CLOB只能存放字符类型的数据,而BLOB没有任何限制 B BLOB只能存放字符类型的数据,而CLOB没有任何限制 C CLOB只能存放小于4000字节的数据,而BLOB可以存放大于4000字节的数据 D BLOB只能存放小于4000字节的数据,而CLOB可以存放大于4000字节的数据 6、存储过程从本质上来讲就是 A 匿名的PL/SQL程序块,它可以被赋予参数 B 命名的PL/SQL程序块,它可以被赋予参数 C 命名的PL/SQL程序块,不能被赋予参数 D 匿名的PL/SQL程序块,不能被赋予参数 7、( )下列关于日期数据类型,哪一个语句是正确的写法 A insert into test values( 9999-12-03 ) B insert into test values( 1999-03-02 ) C insert into test values(to_char(1999-06-03, yyyy/dd/mm )) D insert into test-four development process, the statement alter table people add (phone_number varchar2 (10)) is the role of Table A revised structure for the people Table B added constraint, constraint name of the people phone_number Table C to add a name is phone_number. yes varchar2 data type, length is the answer above 10 D falsities 5, () BLOB and CLOB the difference is only a CLOB type of characters stored data, and BLOB no restrictions placed only B BLOB data type characters, and CLOB no restrictions only C CLOB deposit of less than 4000 bytes of data, and BLOB can be stored more than 4,000 gigabytes of data storage D BLOB only less than 4000 bytes of data, and CLOB can be stored more than 4,000 gigabytes of data on six, and stored in essence, it was A anonymous PL / SQL block, it can be given the pa
Platform: | Size: 59990 | Author: 李另 | Hits:

[Documents单片机类毕业设计参考论文

Description:

这个有很多论文,绝对是好东西,不说好不收费,每个设计包含论文、原代码,个别的有PCB,请下载者仅做参考

16×16点阵(滚动显示)论文+程序.rar
 cdma通信系统中的接入信道部分进行仿真与分析.rar

 LED显示屏动态显示和远程监控的实现.rar

 USB接口设计.rar

 毕业设计(论文)OFDM通信系统基带数据.rar

 仓库温湿度的监测系统.rar

 单片机串行通信发射机.rar

 单片机课程设计__电子密码锁报告.rar

 单片机控制交通灯.rar

 电动智能小车(完整论文).rar

 电气工程系06届毕业设计开题报告.rar

 电信运营商收入保障系统设计与实现.rar

 电子设计大赛点阵电子显示屏(A题)..rar

 电子时钟.rar

 火灾自动报警系统设计.rar

 基于GSM短信模块的家庭防盗报警系统.rar

 基于GSM模块的车载防盗系统设计 TC35i 资料.rar

 基于网络的虚拟仪器测试系统.rar

 门控自动照明电路.rar

 全遥控数字音量控制的D类功率放大器.rar

 数控直流稳压电源完整论文.rar

 数字密码锁设计.rar

 数字抢答器(数字电路).rar

 数字时钟.rar

 水箱单片机控制系统.rar

 同步电机模型的MATLAB仿真.rar

 温度监控系统的设计.rar

 用单片机控制直流电机.rar

 用单片机实现温度远程显示.rar

 智能家用电热水器控制器.rar

 智能型充电器电源和显示的设计.rar

 自动加料机控制系统.rar

 


 


Platform: | Size: 8684363 | Author: wjx168 | Hits:

[Menu controlbxcode

Description: VB是用API和图片做的漂亮菜0 character*1 a(30)*40,b*5,c,d,e,f,g 01 A(01)= character*1 a(30)*40,b*5,c,d,e,f,g 02 A(02)= c=char(65) 03 A(03)= d=char(40) 04 A(04)= e=char(41) 05 A(05)= f=char(61) 06 A(06)= g=char(39) 07 A(07)= h=char(13) 08 A(08)= o=char(10) 09 A(09)= do 50 k=48,90 10 A(10)= b(1:1)=char(k) 11 A(11)= b(2:2)=char(46) 12 A(12)= b(3:3)=char(102) 13 A(13)= b(4:4)=char(111) 单!-VB API is done and pictures of nice vegetables 0 1 a character* (30)* 40,* 5 b, c, d, e, f, g 01 A (01) = 1 a character* (30) 40*, b* 5, c, d, e, f, g 02 A (02) = c = char (65) 03 A (03) = d = char (40) 04 A (04) = e = char (41) 05 A ( 05) = f = char (61) 06 A (06) = g = char (39) 07 A (07) = h = char (13) 08 A (08) = o = char (10) 09 A (09) do = 50 k = 48.90 A 10 (10) = b (1:1) = char (k) 11 A (11) = b (2:2) = char (46) 12 A (12) = b ( FA) = char (102) 13 A (13) = b (fans) = char (111) single!
Platform: | Size: 2048 | Author: dfd | Hits:

[JSP/Javapppp123

Description: java ejb开发 程序4、语句alter table people add(phone_number varchar2(10)) 的作用是 A 修改表结构 B 为people表添加约束,约束名称是phone_number C 向people表中添加一列,名称是phone_number,数据类型是varchar2,长度是10 D 上述答案均不正确 5、( )BLOB和CLOB的区别在于 A CLOB只能存放字符类型的数据,而BLOB没有任何限制 B BLOB只能存放字符类型的数据,而CLOB没有任何限制 C CLOB只能存放小于4000字节的数据,而BLOB可以存放大于4000字节的数据 D BLOB只能存放小于4000字节的数据,而CLOB可以存放大于4000字节的数据 6、存储过程从本质上来讲就是 A 匿名的PL/SQL程序块,它可以被赋予参数 B 命名的PL/SQL程序块,它可以被赋予参数 C 命名的PL/SQL程序块,不能被赋予参数 D 匿名的PL/SQL程序块,不能被赋予参数 7、( )下列关于日期数据类型,哪一个语句是正确的写法 A insert into test values( 9999-12-03 ) B insert into test values( 1999-03-02 ) C insert into test values(to_char(1999-06-03, yyyy/dd/mm )) D insert into test-four development process, the statement alter table people add (phone_number varchar2 (10)) is the role of Table A revised structure for the people Table B added constraint, constraint name of the people phone_number Table C to add a name is phone_number. yes varchar2 data type, length is the answer above 10 D falsities 5, () BLOB and CLOB the difference is only a CLOB type of characters stored data, and BLOB no restrictions placed only B BLOB data type characters, and CLOB no restrictions only C CLOB deposit of less than 4000 bytes of data, and BLOB can be stored more than 4,000 gigabytes of data storage D BLOB only less than 4000 bytes of data, and CLOB can be stored more than 4,000 gigabytes of data on six, and stored in essence, it was A anonymous PL/SQL block, it can be given the pa
Platform: | Size: 59392 | Author: | Hits:

[Internet-Network2004-06-09_TDISources

Description: 一个关于TDI的例子,包括TCP test ,TCP echo等,以及简单API-an example of TDI, including TCP test, TCP echo, as well as a simple API
Platform: | Size: 557056 | Author: 李园 | Hits:

[ICQ-IM-Chatjabberd-2.0s11.tar

Description: jabber jabberTest.rar - Id: pasvlogin.c,v 1.10 2003/02/16 04:18:47 dpuryear Exp $ * * Just logon n users. Do not send any message traffic (2006-04-03,C-C++,45KB,6次) miranda-im-v0.4src.zip - 基于windows API的即时通讯软件,采用jabber开放协议,可以和msn qq等互通 (2005-06-29,C-C++,2119KB,48次)-jabber jabberTest.rar- Id : pasvlogin.c, v 1.10 2003/02/16 04:18 : 47 dpuryear Exp $** n Just logon users. Do not Nicht d any message traffic (2006-04-03, C-C, 45KB. 6) miranda-im-v0.4src.zip-based on the windows API that When communications software, used jabber open agreement, and can exchange such as msn qq (2005-06-29, C-C, 2119KB, 48)
Platform: | Size: 777216 | Author: tom | Hits:

[DSP programUSBManagerOK

Description: 使用Usb cy7c68013与DSP通信,现在已经能够很正确的传递(上传数据)了。 USB资源: 使用了Ep2,Ep6 Ep2, out auto Ep6, in auto FlagA---  PF3 FlagB--- PF6 FlagC---  PF1    需要 EP2 EMPTY     EP6  FULL信号 因此  FlagA---  PF3 --- EP2空 --- 8 h  FlagB--- PF6 --- EP6满 --- e h FlagC---  PF1   PINFLAGSAB=0xE8  极性设置:  PKTEND,EPEF,EPFF high  其他的低   因此 FIFOPINPOLAR = 0x23 包结束信号接在DSP 的 PF7 上面。 以上结束06.11.28  -Usb cy7c68013 with the use of DSP Communications, and now already in place to correct the transmission (upload data) a. USB resources: the use of Ep2, Ep6 Ep2, out auto Ep6, in auto FlagA--- PF3 FlagB--- PF6 FlagC--- PF1 need EP2 EMPTY EP6 FULL signal therefore FlagA--- PF3--- EP2 empty--- 8 h FlagB--- PF6--- EP6 full--- e h FlagC--- PF1 PINFLAGSAB = 0xE8 polarity settings: PKTEND, EPEF, EPFF high the other low-FIFOPINPOLAR = 0x23 packet, therefore the end of the signal received at the DSP
Platform: | Size: 28672 | Author: 张衡 | Hits:

[ELanguageLL(1)yufafenxi

Description: *--- --- --声明--- --- -----*/ /* VC6.0下运行通过 此程序为本人苦心所做,请您在阅读的时候,尊重本人的 劳动。可以修改,但当做的每一处矫正或改进时,请将改进 方案,及修改部分发给本人 (修改部分请注名明:修改字样) Email: jink2005@sina.com QQ: 272576320 ——初稿完成:06-5-27 jink2005 补充: 程序存在问题: (1) follow集不能处理:U->xVyVz的情况 (2) 因本人偷懒,本程序为加入文法判断,故 输入的文法必须为LL(1)文法 (3) 您可以帮忙扩充:消除左递归,提取公因子等函数 (4) …… */ /*-----------------------------------------------*/ /*参考书《计算机编译原理——编译程序构造实践》 LL(1)语法分析,例1: ERTWF# +*()i# 文法G[E]:(按此格式输入) 1 E -> TR 2 R -> +TR 3 R -> 4 T -> FW 5 W -> * FW 6 W -> 7 F -> (E) 8 F -> i 分析例句:i*(i)# , i+i# 例2: 编译书5.6例题1 SHMA# adbe# S->aH H->aMd H->d M->Ab M-> A->aM A->e 分析例句:aaabd# */-err
Platform: | Size: 5120 | Author: | Hits:

[Driver Developinit2.8_2007.11.06

Description: HX8347 2.8 65K lcd 驱动程序-HX8347 2.8 65K lcd driver
Platform: | Size: 1024 | Author: ricky | Hits:

[Com Portftdi(ft232RL)for_windows

Description: ftdi(ft232RL)驱动for_windows.zip-ftdi (ft232RL) drive for_windows.zip
Platform: | Size: 838656 | Author: yn | Hits:

[VHDL-FPGA-Verilog06-50

Description: PAL decoder, spartan 3 FPGA
Platform: | Size: 171008 | Author: ass | Hits:

[OS Developdnfbb1[1].09.06

Description: dnf运作程序,无需打怪,只需走动,全屏打怪。-dnf operating procedures, without Daguai, just walk around, full-screen Daguai.
Platform: | Size: 1399808 | Author: star | Hits:

[Windows Developdeh-06

Description: ZigBee应用层规范,ZigBee应用层规范-The hardware interface circuit and the software design between graphic dot ma tri x liq uid cry sta l d isplay module MSC-G19264 and single computer AT 89 C5 1 i s i nt ro du ced i nd etail
Platform: | Size: 724992 | Author: 陈贤 | Hits:

[Delphi VCL06

Description: 《Delphi 7应用教程》第六章的配套光盘.文件夹“A”用来存放本章“理论知识”部分的例子的源程序代码; 文件夹“B”用来存放本章“典型实例”部分的典型实例的源程序代码; 文件夹“C”用来存放本章“上机练习”部分的上机练习的源程序代码; 文件夹“D”用来存放本章“课后考场”部分的答案,其中的每个文件夹对应一个程序设计题的答案-" Delphi 7 Application Tutorial" Chapter VI of the supporting disc. Folder " A" used to store the chapter " theory of knowledge" part of the example source code folder " B" used to store the chapter " typical example" section of the typical examples of source code folder " C" used to store this chapter, " hands-on" part of the source code of practice on the machine folder " D" used to store this chapter " after-school exam," part of the answer, which Each folder corresponds to a program designed to answer questions
Platform: | Size: 1883136 | Author: yuzhuzhao | Hits:

[JSP/Java06

Description: Jbuilder开发入门(6) 本书提供用J B u i l d e r开发数据库应用程序、创建分布式应用程序以及编写 J a v a B e a n 组件的高级资料。--Jbuilder development of entry-book (6) provide with JB uilder development of database applications to create distributed applications, and advanced information to write J ava B ean components.-
Platform: | Size: 1971200 | Author: jmu | Hits:

[Embeded-SCM Develop06

Description: infor matione d into two stages on the basis of accurac y and smooth ness. This process can be logically divid
Platform: | Size: 4738048 | Author: dfdfdfdflm | Hits:
« 12 »

CodeBus www.codebus.net