Welcome![Sign In][Sign Up]
Location:
Search - v.32

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 resourcehuffman

Description: 实现最优二叉树的构造;在此基础上完成哈夫曼编码器与译码器。 假设报文中只会出现如下表所示的字符: 字符 A B C D E F G H I J K L M N 频度 186 64 13 22 32 103 21 15 47 57 1 5 32 20 57 字符 O P Q R S T U V W X Y Z , . 频度 63 15 1 48 51 80 23 8 18 1 16 1 6 2 要求完成的系统应具备如下的功能: 1.初始化。从终端(文件)读入字符集的数据信息,。建立哈夫曼树。 2.编码:利用已建好的哈夫曼树对明文文件进行编码,并存入目标文件(哈夫曼码文件)。 3.译码:利用已建好的哈夫曼树对目标文件(哈夫曼码文件)进行编码,并存入指定的明文文件。 4.输出哈夫曼编码文件:输出每一个字符的哈夫曼编码。
Platform: | Size: 132535 | Author: 张娟 | Hits:

[ActiveX/DCOM/ATLCORDIC_ip

Description: cordic IP core Features Each file is stand-alone and represents a specific configuration. The 4 parameters are: Rotation or Vector Mode Vector Precision Angle Precision Number of Cordic Stages All designs are pipelined with a synchronous enable and reset. The pipeline latency equals 2 clock cycles plus the number of cordic stages. The configuration parameters are coded in the file names: cf_cordic_r_32_16_12.v r : Cordic Mode. r = Rotation, v = Vectoring 32 : Precision of the individual vector components. 16 : Precision of the angle. 12 : Number of cordic stages. Current configurations: cf_cordic_r_8_8_8 cf_cordic_v_8_8_8 cf_cordic_r_16_16_16 cf_cordic_v_16_16_16 cf_cordic_r_18_18_18 cf_cordic_v_18_18_18 cf_cordic_r_32_32_32 cf_cordic_v_32_32_32
Platform: | Size: 458196 | Author: abcoabco | Hits:

[Other resourcewb_rtc

Description: // -*- Mode: Verilog -*- // Filename : wb_master.v // Description : Wishbone Master Behavorial // Author : Winefred Washington // Created On : 2002 12 24 // Last Modified By: . // Last Modified On: . // Update Count : 0 // Status : Unknown, Use with caution! // Description Specification // General Description: 8, 16, 32-bit WISHBONE Master // Supported cycles: MASTER, READ/WRITE // MASTER, BLOCK READ/WRITE // MASTER, RMW // Data port, size: 8, 16, 32-bit // Data port, granularity 8-bit // Data port, Max. operand size 32-bit // Data transfer ordering: little endian // Data transfer sequencing: undefined
Platform: | Size: 8076 | Author: 姓名 | Hits:

[Embeded-SCM Developc54xdtmf

Description:
Platform: | Size: 103424 | Author: flight_bai | Hits:

[OtherDTMF原理

Description: 本文章说明一个可以快速识别和产生DTMF的DSP算法原理!里面详细说明了DTMF的原理和算法公式-a note of this article can quickly identify and generate DTMF DSP algorithm principle! Inside a detailed description of the DTMF principle and algorithm formula
Platform: | Size: 82944 | Author: vv | Hits:

[WEB CodeMD5-32

Description: MD5加密32位,ASP VB脚本的.MD5加密 ,ASP VB脚本的.-MD5 Encryption 32, ASP VB Script. MD5 encryption, ASP VB Script.
Platform: | Size: 3072 | Author: 张卫锋 | Hits:

[SCMsgs32

Description: Verlog HDL 写得一款32路方波发生器,例子是4路可以自己加,相位可调,频率可调,占空比可调。具体参见readme.doc.此处只提供了源码包含顶层模块sgs32.v 子模块dds.v和pll设置模块altp.v及波形驱动文件-Verlog HDL write a 32 square-wave generator, for example, is able to add 4-way, phase adjustable, adjustable frequency, adjustable duty cycle. See readme.doc. Here only provide a source module that contains the top-level sub-modules sgs32.v settings dds.v and pll module altp.v and waveform-driven document
Platform: | Size: 59392 | Author: TTHR | Hits:

[matlabfangzhen

Description: matlab 代码,实现了ITU-T V.32建议的 modem 整体仿真实现。-matlab code, implementation of the ITU-T V.32 proposed modem achieve the overall simulation.
Platform: | Size: 2050048 | Author: 李黎明 | Hits:

[VHDL-FPGA-VerilogLatticeMico8_v3_0_Verilog

Description: The LatticeMico8™ is an 8-bit microcontroller optimized for Field Programmable Gate Arrays (FPGAs) and Crossover Programmable Logic Device architectures from Lattice. Combining a full 18-bit wide instruction set with 16 or 32 General Purpose registers, the LatticeMico8 is a flexible Verilog and VHDL reference design suitable for a wide variety of markets, including communications, consumer, computer, medical, industrial, and automotive. The core consumes minimal device resources, less than 200 Look Up Tables (LUTs) in the smallest configuration, while maintaining a broad feature set.-The LatticeMico8™ is an 8-bit microcontroller optimized for Field Programmable Gate Arrays (FPGAs) and Crossover Programmable Logic Device architectures from Lattice. Combining a full 18-bit wide instruction set with 16 or 32 General Purpose registers, the LatticeMico8 is a flexible Verilog and VHDL reference design suitable for a wide variety of markets, including communications, consumer, computer, medical, industrial, and automotive. The core consumes minimal device resources, less than 200 Look Up Tables (LUTs) in the smallest configuration, while maintaining a broad feature set.
Platform: | Size: 1155072 | Author: 郭豪偉 | Hits:

[Crack HackVMProtect

Description: VMProtect 简介 VMProtect 是新一代的软件保护系统,不像其它常见的保护系统,VMProtect 可以修改应用程序的源代码。VMProtect 将原文件的部分代码转换为在虚拟机中运行的字节码。您可以将虚拟机想像成带有不同于 Intel 8086 处理器指令系统的虚拟处理器;例如,虚拟机没有比较两个操作数的指令,也没有条件跳转和无条件跳转等。 支持的编译器: Delphi Borland C Builder Visual C/C++ Visual Basic (native) Virtual Pascal 支持的文件类型(32 位和 64 位): EXE DLL BPL OCX SYS 支持的操作系统: Windows 95/98 Windows ME Windows NT Windows 2000 Windows XP Windows 2003 Windows Vista-标准类 TObject = class constructor Create procedure Free end TPersistent = class(TObject) procedure Assign(Source: TPersistent) end TStrings = class(TPersistent) function Add(S: String): Integer procedure Append(S: String) procedure AddStrings(Strings: TStrings) procedure Clear procedure Delete(Index: Integer) function IndexOf(const S: String): Integer procedure Insert(Index: Integer S: String) procedure LoadFromFile(FileName: String) procedure SaveToFile(FileName: String) property Count: Integer read property Text: String read write property CommaText: String read write property Strings[Index: Integer]: String read write property Objects[Index: Integer]: TObject read write end TDuplicates = (dupIgnore, dupAccept, dupError) TNotifyEvent = procedure(Sender: TObject) TStringList = class(TStrings) function Find(S: String var Index: Integer): Boolean procedure Sort property Duplicates:
Platform: | Size: 16384 | Author: cxzhack | Hits:

[Crack HackDelphi

Description: VMProtect 简介 VMProtect 是新一代的软件保护系统,不像其它常见的保护系统,VMProtect 可以修改应用程序的源代码。VMProtect 将原文件的部分代码转换为在虚拟机中运行的字节码。您可以将虚拟机想像成带有不同于 Intel 8086 处理器指令系统的虚拟处理器;例如,虚拟机没有比较两个操作数的指令,也没有条件跳转和无条件跳转等。 支持的编译器: Delphi Borland C Builder Visual C/C++ Visual Basic (native) Virtual Pascal 支持的文件类型(32 位和 64 位): EXE DLL BPL OCX SYS 支持的操作系统: Windows 95/98 Windows ME Windows NT Windows 2000 Windows XP Windows 2003 Windows Vista -标准类 TObject = class constructor Create procedure Free end TPersistent = class(TObject) procedure Assign(Source: TPersistent) end TStrings = class(TPersistent) function Add(S: String): Integer procedure Append(S: String) procedure AddStrings(Strings: TStrings) procedure Clear procedure Delete(Index: Integer) function IndexOf(const S: String): Integer procedure Insert(Index: Integer S: String) procedure LoadFromFile(FileName: String) procedure SaveToFile(FileName: String) property Count: Integer read property Text: String read write property CommaText: String read write property Strings[Index: Integer]: String read write property Objects[Index: Integer]: TObject read write end TDuplicates = (dupIgnore, dupAccept, dupError) TNotifyEvent = procedure(Sender: TObject) TStringList = class(TStrings) function Find(S: String var Index: Integer): Boolean procedure Sort property Duplicates:
Platform: | Size: 4096 | Author: cxzhack | Hits:

[DSP programTELECOM3

Description: This file contains program files associated with the paper titled "Viterbi Implementation on the TMS320C5x for V.32 Modems", Telecom Applications With The TMS320C5x DSPs, Application Book, 1994, SPRA033.
Platform: | Size: 10240 | Author: MuckChow | Hits:

[Program docT-REC-V[1].32-199303-I!!PDF-E

Description: itu-t recommendation standard v.32
Platform: | Size: 148480 | Author: sradu | Hits:

[JSP/JavaUltraEdit-32.v11.00

Description: 文字编辑器,能自动识别Java包里面的提示符-Text editor, Java package which can automatically identify the prompt ...
Platform: | Size: 5052416 | Author: 张先忠 | Hits:

[File FormatV.32-standard-under-32QAM

Description: V.32标准下32QAM_–TCM_的编程实现,供参考,相互学习-V.32 standard under 32QAM_-TCM_ of programming
Platform: | Size: 93184 | Author: 王洪涛 | Hits:

[Driver Developnbp-0.32-public

Description: 硬件虚拟化的一个例子,包括Intel VT,AMD-V 技术-An example of hardware virtualization
Platform: | Size: 134144 | Author: 杨愉存 | Hits:

[WEB CodeWimpy-Rave-v-2.0.32-cracked

Description: 网页播放器Wimpy Rave v 2.0.32的破解激活版,官方链接http://www.wimpyplayer.com/products/wimpy_rave.html-Web player Wimpy Rave v 2.0.32 crack activation version, the official link http://www.wimpyplayer.com/products/wimpy_rave.html
Platform: | Size: 3371008 | Author: 丁飞己 | Hits:

[VHDL-FPGA-Verilogfloat_2_int.v

Description: 最全的,最简单,32位浮点数转整数,32位整数转浮点数,直接可以移植,已经测试过好用。(The most complete, the simplest, 32 bit floating-point integer, 32 integer floating point number, can be directly transplanted, has been tested, easy to use.)
Platform: | Size: 1024 | Author: 那里的星空 | Hits:

[Delphi VCLTRichView.v.16.10.0.x86-x64.Src

Description: TRichView.v.16.10.0.x86-x64.Src.rar 支持最新的delphi 10.2 亲测可用,包含32位,64位源码(TRichView.v.16.10.0.x86-x64.Src.rar Support the latest Delphi 10.2 32 - bit, 64 - bit source code)
Platform: | Size: 55810048 | Author: 宋浩 | Hits:
« 12 3 »

CodeBus www.codebus.net