Welcome![Sign In][Sign Up]
Location:
Search - ti c

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:

[DSP programF2812 fft 源程序 TI例程

Description: F2812 fft 源程序 TI例程。作DSP的新手参考TI的例程是最快的学习途径。-This is fft source program example of F2812. It is written by TI. It is the fastest way for DSP starters to learn the examples of TI.
Platform: | Size: 2048 | Author: 丘平 | Hits:

[DSP programDSP+Mp3+USB+FAT12的所有源程序(C语言编写)。

Description: DSP+Mp3+USB+FAT12的所有源程序(C语言编写)。用TI的DSP写的U盘接口程序,实现USB、MP3-DSP MP3 USB FAT12 all source (C language). TI's DSP with the U-write interface, USB, MP3
Platform: | Size: 92160 | Author: 王明亮 | Hits:

[OtherTI-DSPCODE

Description: TI DSP的C语言和汇编语言的源代码,比较适用,可以作为初学参考-TI DSP C language and assembly language source code, more applicable, reference can be used as beginners
Platform: | Size: 40960 | Author: smartchen | Hits:

[DSP programTI-DSP

Description: TI公司的DSP程序库,包括C语言和汇编语言的程序库,希望对大家有益 -TI's DSP libraries, including C and Assembly Language for the procedure, hoping to benefit everyone
Platform: | Size: 39936 | Author: Bruce | Hits:

[DSP programDSP_Algorithm

Description: DSP算法C语言源代码—— TI公司的TMS320C5000 -DSP algorithm C language source code-- TI's TMS320C5000
Platform: | Size: 23552 | Author: david | Hits:

[DSP programC54_info

Description: ti tms320c54x c语言源码 对初学者帮助-ti c tms320c54x language source code to help beginners
Platform: | Size: 361472 | Author: 刘云生 | Hits:

[OtherOFDMA.Resource.Allocation.Simulations.c

Description: This set of simulation files performs a computational complexity performance comparison of the two methods mentioned in the paper. The source is ANSI-C compliant, hence any C-compiler can be used to compile the source code. It has been tested using Visual Studio.net C++ and TI code composer studio C compiler for the TMS320C6701. Note that the performance comparison may be different for different platforms.-This set of simulation files performs a com putational complexity performance compariso n of the two methods mentioned in the paper. The s ource is ANSI-C compliant. hence any C-compiler can be used to compile the s ource code. It has been tested using Visual Stud io.net C and TI code composer studio C compiler f or the TMS320C6701. Note that the performance c omparison may be different for different platf orms.
Platform: | Size: 592896 | Author: 马文 | Hits:

[SCM430-ht1621

Description: Ti msp430f149 用c语言编写的 ht1621 LCD的驱动程序-Ti c msp430f149 language with the ht1621 LCD Driver
Platform: | Size: 2048 | Author: qinyu | Hits:

[OtherCCS

Description: ti公司的ccs中文教程。。非常不错-ti
Platform: | Size: 617472 | Author: 孙广会 | Hits:

[Special Effectsmotiotest

Description: TI的ccs开发环境,DM642上跑的源程序,做运动检测-TI development environment ccs of, DM642 running the source code, to do Motion Detection
Platform: | Size: 962560 | Author: 简思平 | Hits:

[OtherICETEK-VC5509-C

Description: ICETEK_VC5509_C的硬件原理图,泰瑞公司开发的针对TI C5509A DSP的评估版。包含xilinx FPGA 及语音解码芯片TLV320AIC23等的连接,可借鉴性强 -ICETEK_VC5509_C hardware schematics, Terry developed for the TI C5509A DSP evaluation version. Contains xilinx FPGA and voice decoder chip TLV320AIC23 connections, etc., can draw on strong
Platform: | Size: 66560 | Author: 一凡 | Hits:

[EditorCCS-simple-guide

Description: TI的CCS(Code.Composer.Studio)的入门指导教程,PDF版文件,简体中文。-TI s CCS (Code.Composer.Studio) entry guide tutorial, PDF version of a document, Simplified Chinese.
Platform: | Size: 693248 | Author: yushun | Hits:

[DSP programDm6446Ubl

Description: 這是TI dm6446 EVM board 的UBL,它支源 Nand/NOR/UART 開機,此為CCS 裡的專案,下載解開後直接邊譯即可-This is TI dm6446 EVM board of UBL, the source of its support Nand/NOR/UART boot, this is a project in the CCS, download and unzip, then you can be directly compile it
Platform: | Size: 731136 | Author: mingkuang tsai | Hits:

[OtherTMS320C6000CSLAPIReferenceGuide

Description: 讲解了TI提供的CSL函数。详细描述了,每个可供调用函数的用法。-The TMS320C6000 Chip Support Library (CSL) is a set of application programming interfaces (APIs) used to configure and control all on-chip peripherals. It is intended to make it easier for developers by eliminating much of the tedious work usually needed to get algorithms up and running in a real system.
Platform: | Size: 2081792 | Author: 李继唐 | Hits:

[CSharp97288396Goertzel

Description: goartzel implemtntation algoritm in c goart zel implemtntation algoritm in c goartzel implemtntation algoritm in c -goartzel implemtntation algoritm in c goartzel implemtntation algoritm in c goartzel implemtntation algoritm in c goartzel implemtntation algoritm in c
Platform: | Size: 12288 | Author: kalafior | Hits:

[DSP programTI-C-Programming

Description: TI C Programming TMS320C55 C Characteristics
Platform: | Size: 18432 | Author: stan1860 | Hits:

[SCMTI.C

Description: TI公司MSP430源程序代码C语言,比较齐全-TI company‘s MSP430 Source code of C language
Platform: | Size: 144384 | Author: 史博闻 | Hits:

[DSP programTi.Math.Lib.Note.spru514n

Description: TMS320C28x Optimizing C/C++ Compiler v17.6.0.STS
Platform: | Size: 814080 | Author: 老愚 | Hits:

[OtherTI公司ZIGBEE实现的源代码

Description: TI公司ZIGBEE实现的C源代码,大神瞧瞧呀!(Source code of Ti ZigBee)
Platform: | Size: 550912 | Author: jerryqrst | Hits:
« 12 3 4 5 6 7 8 9 10 ... 38 »

CodeBus www.codebus.net