Welcome![Sign In][Sign Up]
Location:
Search - TI 24

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:

[assembly languageADS1253

Description: 本人编写的TI 24为ADC功能测试程序-I prepared for the TI 24 ADC functional test procedures
Platform: | Size: 883 | Author: TAOXY | Hits:

[Other resourceDSP2812_BLDCM

Description: 程序是我用DSP2812开发的无刷直流电机控制程序,程序是在TI公司的BLDC3_1软件的基础上构造的,实现了无刷直流电机的速度环PID控制,并且可以进行无刷直流电机的高级控制算法研究,扩展及其方便。 其中,无刷直流电机控制系统是有HALL传感器的系统,电机是24V3000rpm驱动板是类似TI公司的DMC1500板卡。欢迎交流-procedure I used DSP2812 development of the brushless DC motor control procedures, TI is in the process of BLDC3_1 software companies on the basis of the structure, Implementation of the brushless DC motor velocity loop PID control, and can brushless DC motor control algorithm senior research, extension and its convenience. Among them, brushless DC motor control system is a sensor system HALL, 24 V3000rpm motor-driven plate is similar to TI's DMC1500 Card. Welcome exchange
Platform: | Size: 304625 | Author: 李洪科 | Hits:

[Embeded-SCM Developmotorcontrol

Description: 附件程序是我用DSP2812开发的无刷直流电机控制程序,程序是在TI公司的BLDC3_1软件的基础上构造的,实现了无刷直流电机的速度环PID控制,效果可以。 其中,无刷直流电机是有HALL传感器的系统,所以在转速测量上还需要进一步的改进(如果要求精确的话)。电机是24V3000rpm~~~;驱动板是类似TI公司的DMC1500?板卡,所以可以参考它的说明(只针对信号的连接的参考)-Annex I use the procedure is the development of the DSP2812 brushless DC motor control procedures, TI is in the process of BLDC3_1 software companies on the basis of the structure, Implementation of the brushless DC motor velocity loop PID control, the effect can be. Among them, brushless DC motor are HALL sensor system So speed measurements need further improvements (if the precise words). Motor V3000rpm is 24 ~ ~ ~; Market-driven companies like TI DMC1500? Card, we can refer to it (only signal against a reference link)
Platform: | Size: 307534 | Author: zht | Hits:

[Linux-Unixnetpbm-10.26.24

Description: linux下将各类格式图片转换工具,包含bmp,jpeg,gif,ppm,jpg,pcx,png,ti-under linux type of format conversion tools pictures, including bmp, jpeg, gif, ppm, jpg, pcx, png, tiff, etc.
Platform: | Size: 2540150 | Author: y | Hits:

[Other resourceMSC1210A2D

Description: TI 集成高性能24位A/D转换器的8052 核心单片机MSC1210 A/D转换代码。-TI integrated high-performance 24-bit A / D converters 8052 microcontroller core MSC1210 A / D conversion code.
Platform: | Size: 85430 | Author: 李劲 | Hits:

[Other resourceMSC1210DataFlash

Description: TI 集成高性能24位A/D转换器的8052 核心单片机MSC1210 DATA区的FLASH读写代码。-TI integrated high-performance 24-bit A / D converters 8052 microcontroller core MSC1210 DAT A FLASH of reading and writing code.
Platform: | Size: 102796 | Author: 李劲 | Hits:

[Other resourceMSC1210Temperature

Description: TI 集成高性能24位A/D转换器的8052 核心单片机MSC1210 内置温度传感器测量代码。-TI integrated high-performance 24-bit A / D converters 8052 MSC1210 embedded microcontroller core temperature Sensor Measurement code.
Platform: | Size: 41443 | Author: 李劲 | Hits:

[Other resourceMSC1210pwm

Description: TI 集成高性能24位A/D转换器的8052 核心单片机MSC1210 PWM发生器代码。-TI integrated high-performance 24-bit A / D converters 8052 microcontroller core MSC1210 PWM code generator.
Platform: | Size: 21190 | Author: 李劲 | Hits:

[Other resourcemsc1211

Description: TI德州仪器高性能模拟数字混合处理器msc1211的程序,主要侧重于其内部高精度24位ad以及串口通信,这个是我做的一个项目上用的-TI Texas Instruments high-performance analog-to-digital mix processor msc1211 procedures, mainly focused its internal high-precision 24 ad and serial communication, this is what I am doing an item on the
Platform: | Size: 14886 | Author: fdy | Hits:

[Other resourceADs1258-Chinese

Description: TI生产的24位模数转换芯片ADs1258的中文翻译资料,可以帮助使用者用更快的时间读懂芯片结构进而投入开发工作,缩短前期准备时间。
Platform: | Size: 372316 | Author: 王艳艳 | Hits:

[DSP programdsp2407

Description: TI TMS320LF2407 源码-There are some source programs of TMS320LF2407
Platform: | Size: 229376 | Author: 高斌 | Hits:

[DSP programtms320lf2407

Description: TI公司生产的TMS320LF2407的一个很多模块编程实例,很有用的。-TI production TMS320LF2407 a lot module programming examples, very useful.
Platform: | Size: 97280 | Author: wjx | Hits:

[assembly languageADS1253

Description: 本人编写的TI 24为ADC功能测试程序-I prepared for the TI 24 ADC functional test procedures
Platform: | Size: 1024 | Author: | Hits:

[Linux-Unixnetpbm-10.26.24

Description: linux下将各类格式图片转换工具,包含bmp,jpeg,gif,ppm,jpg,pcx,png,ti-under linux type of format conversion tools pictures, including bmp, jpeg, gif, ppm, jpg, pcx, png, tiff, etc.
Platform: | Size: 2540544 | Author: y | Hits:

[SCMmsc1211

Description: TI德州仪器高性能模拟数字混合处理器msc1211的程序,主要侧重于其内部高精度24位ad以及串口通信,这个是我做的一个项目上用的-TI Texas Instruments high-performance analog-to-digital mix processor msc1211 procedures, mainly focused its internal high-precision 24 ad and serial communication, this is what I am doing an item on the
Platform: | Size: 14336 | Author: fdy | Hits:

[DSP programdsp(2407)uart

Description: TI的DSP,TMS32F2407的串口驱动程序,带运行环境,直接下载直接运行就可以。-TI s DSP, TMS32F2407 serial driver, runtime environment with a direct download can be run directly.
Platform: | Size: 16384 | Author: 张辉 | Hits:

[DSP programtms320lf2406

Description: TI公司的TMS320LF2407 DSP的资料。是一个很好的介绍、指导性文件。-TI company s TMS320LF2407 DSP guiding document.
Platform: | Size: 777216 | Author: 余虎 | Hits:

[DSP programads1278-c6727-ccs3v3

Description: ADS1278 24位AD采集,TI 6000 6727 控制程序,-ADS1278 24 Wei AD acquisition, TI 6000 6727 control procedures,
Platform: | Size: 224256 | Author: hu71992 | Hits:

[Software EngineeringHC21.24.421.Witt-OMAP4430

Description: TI 最新A9双核产品OMAP4430开发架构介绍。-Development introduction of the newset A9 Dual core cpu of TI.
Platform: | Size: 233472 | Author: justin | Hits:
« 12 3 »

CodeBus www.codebus.net