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

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:

[Other resourceTI 54x fft

Description: DSP编程代码,FFT算法,经典!! FFT实验 一、 理论: 公式(1)FFT运算公式 FFT并不是一种新的变换,它是离散傅立叶变换(DFT)的一种快速算法。由于我们在计算DFT时一次复数乘法需用四次实数乘法和二次实数加法;一次复数加法则需二次实数加法。每运算一个X(k)需要4N次复数乘法及2N+2(N-1)=2(2N-1)次实数加法。所以整个DFT运算总共需要4N^2次实数乘法和N*2(2N-1)=2N(2N-1)次实数加法。如此一来,计算时乘法次数和加法次数都是和N^2成正比的,当N很大时,运算量是可观的,因而需要改进对DFT的算法减少运算速度。 根据傅立叶变换的对称性和周期性,我们可以将DFT运算中有些项合并。 我们先设序列长度为N=2^L,L为整数。将N=2^L的序列x(n)(n=0,1,……,N-1),按N的奇偶分成两组,也就是说我们将一个N点的DFT分解成两个N/2点的DFT,他们又从新组合成一个如下式所表达的N点DFT: 一般来说,输入被假定为连续、合成的。当输入为纯粹的实数的时候,我们就可以利用左右对称的特性更好的计算DFT。 我们称这样的RFFT优化算法是包装算法:首先2N点实数的连续输入称为“进包”。其次N点的FFT被连续被运行。最后作为结果产生的N点的合成输出是
Platform: | Size: 439370 | Author: 徐克 | Hits:

[Other resourceFlashRW

Description: TI公司DSP开发板DSK6711针对Flash的完整犊写功能,CCS2.x版,C语言环境-TI DSP development board DSK6711 against the integrity calf Flash write function, CCS2.x version, C language environment
Platform: | Size: 8568 | Author: Tony | Hits:

[Other resource5402_dtmf

Description: TI公司DSP开发板DSK5402针对DTMF的完整功能操作与代码,CCS2.x版-TI DSP development board DSK5402 DTMF against the integrity of the operation and function code, CCS2.x version
Platform: | Size: 8272 | Author: Tony | Hits:

[Other resourceSWIO

Description: TI公司DSP开发板DSK6711针对周边IO(LED)的功能显示操作,CCS2.x/3.x版,采用C语言完整编译-TI DSP development board DSK6711 against neighboring IO (LED) display functions operate, CCS2.x/3.x version, complete with C language compiler
Platform: | Size: 5740 | Author: Tony | Hits:

[Other resourceDSK6713_IO

Description: 针对TI公司的DSK6713所发展的IO(LED)范例,容易又实用,CCS2.x/3.x版,采用C语言完整编译-against the DSK6713 TI developed by IO (LED) Examples easily practical. CCS2.x/3.x version, complete with C language compiler
Platform: | Size: 3562 | Author: Tony | Hits:

[Other resourceC6711_predict

Description: 针对TI公司的DSK6711所发展的适应性调适范例,包含完整LMS功能,CCS2.x版,采用C语言完整编译-against TI's DSK6711 developed adaptive adjustment example, LMS includes functional integrity, CCS2.x version, complete with C language compiler
Platform: | Size: 19691 | Author: Tony | Hits:

[Other resourceC6713_poll

Description: 针对TI公司的DSK6713所发展的Audio范例包含Line in/Line out,采用Poll方式,包含完整C语言编译,CCS2.x/CCS3.x版-against the DSK6713 TI developed by Audio Examples include Line in / Li ne out, using Poll, including full C language compiler, version CCS2.x/CCS3.x
Platform: | Size: 14590 | Author: Tony | Hits:

[Other resourceC6713_intr

Description: 针对TI公司的DSK6713所发展的Audio范例包含Line in/Line out,采用中断(Interrupt)的方式,包含完整C语言编译,CCS2.x/CCS3.x版-against the DSK6713 TI developed by Audio Examples include Line in / Li ne out, using interrupts (Interrupt), includes a complete C language compiler. CCS2.x/CCS3.x version
Platform: | Size: 15118 | Author: Tony | Hits:

[DSP program5402_dtmf

Description: TI公司DSP开发板DSK5402针对DTMF的完整功能操作与代码,CCS2.x版-TI DSP development board DSK5402 DTMF against the integrity of the operation and function code, CCS2.x version
Platform: | Size: 8192 | Author: Tony | Hits:

[Othertl431

Description: TL 431 计算工具,TI的431以及其他型号的也可用 方便实用-TL 431 calculation tools, TI
Platform: | Size: 58368 | Author: 古峰 | Hits:

[DSP programintroduction_of_XDM_interface_and_codec_egine

Description: codec engine和xdm是TI DAVINCI系列处理器开发环境中的重要组成部分。本文章是作者阅读了大量TI文档后对这两者的工作原理和如何利用这两个工具进行DSP算法开发的一个全面透彻但很容易理解的分析,包含了作者很多的心血。-xdm is a codec engine, and TI DAVINCI processor development environment an important component of the. The author of this article is to read a lot of these TI documents, after the work of the two principles and how to use these two tools for DSP algorithm development of a comprehensive and thorough but easy to understand analysis, the author includes a lot of hard work.
Platform: | Size: 471040 | Author: zx | Hits:

[ARM-PowerPC-ColdFire-MIPSCCS-V4-user-guide-CHS

Description: CCS V4.0 中文使用指南 TI CCS 4.x用户请参考。有详细的操作步骤! 本人新自操刀-CCS V4.0 Chinese User Guide. TI CCS 4.x users please refer to. Detailed steps! I have a new self-penned
Platform: | Size: 395264 | Author: chanuei | Hits:

[DSP programxloader.tar

Description: 这个是TI公司的OMAP3530的X-loader源码。OMAP3530是Ti公司的新一代ARM+DSP核。-This is TI' s OMAP3530 The X-loader source. OMAP3530 is the company' s new generation of Ti ARM+ DSP core.
Platform: | Size: 577536 | Author: liubin | Hits:

[ARM-PowerPC-ColdFire-MIPSTICCS4.X-Crack

Description: TI CCS4.X的和谐文件,测试过了,好用。-TI CCS4.X harmony files, tested, and easy to use.
Platform: | Size: 2841600 | Author: zhouzhou | Hits:

[Other Embeded programx-load-1.41

Description: 这是ti CORTEX A8处理器 OMAP3530的X-Loader 在pandaboard验证通过! -This is ti CORTEX A8 OMAP3530 processor, the X-Loader in pandaboard verified by!
Platform: | Size: 148480 | Author: 11 | Hits:

[OtherF28xx(X)

Description: TI F28xx(X)模拟接口设计综述)。-TI F28xx ( X ) simulation interface design review).
Platform: | Size: 1420288 | Author: milaoshu | Hits:

[Embeded Linuxx-loader.tar

Description: The code of xloader for TI device.-The code of xloader for TI device
Platform: | Size: 884736 | Author: 李白能 | Hits:

[ELanguageDTP-216.X

Description: Driver TLV320AIC23B.c From TI
Platform: | Size: 120832 | Author: watchara sopangam | Hits:

[Embeded Linuxx-loader-03.00.02.07

Description: ti 达芬奇的xloader,启动代码,对学习达芬奇裸板程序很有帮助-Ti Da Vinci xloader, start code, the learning of the Da Vinci bare board program is very helpful
Platform: | Size: 315392 | Author: 冯坤 | Hits:
« 12 3 »

CodeBus www.codebus.net