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

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:

[SMSGSM 03.40

Description: 来自ETSI的GSM网络的短消息服务规范,事实上这才是每一个搞短信开发的人的第一篇该研读的规范——真正的国际规范!但是我身边的短信开发者却很少知道03.40的意义-from the ETSI GSM network Short Message Service standard, in fact this is an engaging each SMS development of the first study of the norms -- truly international norms! But I know SMS developers 03.40 seldom know the significance of that,
Platform: | Size: 317117 | Author: 殷虎 | Hits:

[Communicationsmscode

Description: 短信息收发有关的规范主要包括GSM 03.38、GSM 03.40和GSM 07.05
Platform: | Size: 61297 | Author: caojiqian | Hits:

[Embeded-SCM DevelopIR-DSY

Description: 红外遥控键值解码1602液晶显示 红外遥控器键值如下: 10 03 01 06 09 1D 1F 0D 19 1B 11 15 17 12 16 4C 40 48 04 00 02 05 54 4D 0A 1E 0E 1A 1C 14 0F 0C
Platform: | Size: 2102 | Author: ox | 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:

[SMSGSM 03.40

Description: 来自ETSI的GSM网络的短消息服务规范,事实上这才是每一个搞短信开发的人的第一篇该研读的规范——真正的国际规范!但是我身边的短信开发者却很少知道03.40的意义-from the ETSI GSM network Short Message Service standard, in fact this is an engaging each SMS development of the first study of the norms-- truly international norms! But I know SMS developers 03.40 seldom know the significance of that,
Platform: | Size: 316416 | 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: 2048 | Author: dfd | Hits:

[Program docsmscode

Description: 短信息收发有关的规范主要包括GSM 03.38、GSM 03.40和GSM 07.05-Messaging-related specification mainly includes GSM 03.38, GSM 03.40 and GSM 07.05
Platform: | Size: 61440 | Author: caojiqian | Hits:

[Embeded-SCM DevelopIR-DSY

Description: 红外遥控键值解码1602液晶显示 红外遥控器键值如下: 10 03 01 06 09 1D 1F 0D 19 1B 11 15 17 12 16 4C 40 48 04 00 02 05 54 4D 0A 1E 0E 1A 1C 14 0F 0C-Infrared remote control key decoder 1602 LCD IR remote control keys are as follows: 10 03 01 0609 1D 1F 0D19 1B 11 1517 12 16 4C40 48 04 0002 05 54 4D0A 1E 0E 1A1C 14 0F 0C
Platform: | Size: 2048 | Author: ox | Hits:

[OpenGL programNEHEOPENGL

Description: NeHe OpenGL(中文) OpengGL 入门必备教程 NeHe SDK 创建基本框架 怎样使用SDK 配置对话框 视口和绘制函数 2D字符 纹理 框架结构 教程目录 01:OpenGL窗口 02:多边形 03:添加颜色 04:旋转 05:3D空间 06:纹理映射 07:光照和键盘 08:混合 09:移动图像 10:3D世界 11:飘动的旗帜 12:显示列表 13:图像字体 14:图形字体 15:纹理图形字 16:雾 17:2D图像文字 18:二次几何体 19:粒子系统 20:蒙板 21:线的游戏 22:凹凸映射 23:球面映射 24:扩展 25:变形 26:反射 27:影子 28:贝塞尔曲面 29:Blt函数 30:碰撞检测 31:模型加载 32:拾取游戏 33:TGA文件 34:地形 35:播放AVI 36:渲染到纹理 37:卡通映射 38:资源文件 39:物理模拟 40:绳子的模拟 41:体积雾气 42:多重视口 43:FreeType库 44:3D 光晕 45:顶点缓存 46:全屏反走样 47:CG顶点脚本 48:轨迹球 -NeHe OpenGL
Platform: | Size: 2690048 | Author: 朱曙鹏 | Hits:

[SMSGSM03.40

Description: 跟短信相关的电信标准gsm03.40,开发短信应用可以参考-With the SMS-related telecommunications standards gsm03.40, developing SMS application can refer to the
Platform: | Size: 317440 | Author: wang | Hits:

[CommunicationHexdistro_Release_2007-06-19_EV_4.40.03

Description: If you do not want to upload source code, you can join
Platform: | Size: 1154048 | Author: sina | Hits:

[MiddleWareSMSPDUCODEC

Description: PDU是用来发送短彩信的一种编码,上述代码为VB彩信pdu解码。-Wish to develop SMS or EMS application? What do you read from your mobile? PDU code. PDU is a format which you send to a phone to send a SMS or an EMS. You can find more in GSM 03.40
Platform: | Size: 106496 | Author: 冯金凤 | Hits:

[AlgorithmEular-Engineering

Description: Euler工程,相邻元素乘积最大。 给了一个20x20的两位数矩阵,其中的红字部分的积为: 26x63x78x14=1788696 那么,任意方向上(上、下、左、右、对角)4个相邻的数的最大乘积是多少?-In the 20x20 grid below, four numbers along a diagonal line have been marked in red. 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21 24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72 21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95 78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92 16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57 86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58 19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40 04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 6
Platform: | Size: 4096 | Author: superman | Hits:

[SMSData-Coding-Scheme

Description: The TP-Data-Coding-Scheme field, defined in GSM 03.40
Platform: | Size: 5120 | Author: Boboux | Hits:

[JSP/JavaJava-time-value-is-compared

Description: 现在是2004-03-26 13:31:40 java时间值比较 过去是:2004-01-02 11:30:24 我现在要获得两个日期差,差的形式为:XX天XX小时XX分XX秒 -It is 2004-03-26 13 : 31: 40Java time value is comparedThe past is: 2004-01-02 11 : 30: 24Now I want to get a two date difference, difference of the form: XX XX XX XX second day hour
Platform: | Size: 1024 | Author: 刘峰 | Hits:

[Special EffectsLaplacian

Description: 拉普拉斯算子,实现边界锐化。拉普拉斯运算是偏导数运算的线性组合[4-6],而且是一种各向同性(旋转不变)的线性运算。包含实验报告以及代码-Enhancement Using the Laplacian (a) Use the programs developed in Projects 03-03 and 03-04 to implement the Laplacian enhancement technique described in connection with Eq. (3.7-5). Use the mask shown in Fig. 3.39(d). (b) Duplicate the results in Fig. 3.40. You will need to download Fig. 3.40(a).
Platform: | Size: 177152 | Author: landy | Hits:

[SCMpressure_sensor

Description: 压力传感器代码,可以做称重设备 综合误差: 0.02 F.S 绝缘电阻: ≥5000MΩ(100VDC) 灵敏度: 1.0±0.1mV/V 激励电压: 9VDC~12VDC 非线性: 0.02 F.S 温度补偿范围: -10℃~+40℃ 滞后: 0.02 F.S 使用温度范围: -20℃~+60℃ 重要性: 0.02 F.S 零点温度影响: 0.03 F.S/10℃ 蠕变: 0.02 F.S/10min 灵敏度温度影响: 0.02 F.S/10℃ 零点输出: ±1 F.S 安全过载范围: 120 输入阻抗: 405±10Ω 极限过载范围: 150 输出阻抗: 350±3Ω 防护等级: IP65 - if(new_result < old_result) { if(new_result<100) { TR1=0 delay_xms(1000) old_result=new_result TR1=1
Platform: | Size: 120832 | Author: hero | Hits:

[Communicationqqiefa008

Description: 短信息收发有关的规范主要包括GSM 03 38,GSM 03 40和GSM 07 05()
Platform: | Size: 62464 | Author: KYklh%26563 | Hits:

[androidklja8

Description: 短信息收发有关的规范主要包括GSM 03 38,GSM 03 40和GSM 07 05()
Platform: | Size: 60416 | Author: Mirabda | Hits:
« 12 »

CodeBus www.codebus.net