Welcome![Sign In][Sign Up]
Location:
Search - V.42

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 resourceXMLlToolbox2

Description: The XML Toolbox converts MATLAB data types (such as double, char, struct, complex, sparse, logical) of any level of nesting to XML format and vice versa. For example, >> project.name = MyProject >> project.id = 1234 >> project.param.a = 3.1415 >> project.param.b = 42 becomes with str=xml_format(project, off ) \"<project> <name>MyProject</name> <id>1234</id> <param> <a>3.1415</a> <b>42</b> </param> </project>\" On the other hand, if an XML string XStr is given, this can be converted easily to a MATLAB data type or structure V with the command V=xml_parse(XStr).
Platform: | Size: 214576 | Author: leiming691128 | Hits:

[Develop ToolsDelphi7_Lite_Full_20110501

Description: 【Borland是一家令人敬仰的公司,當值Borland已成往事之際,謹以此產品獻給曾經的Borland,紀念已經仙逝的Borland,藉以緬懷Borland傳奇中的經(精)典Delphi7.本產品僅供學習交流之用,未與任何盈利為目的,請勿用於任何非法的商業用途,否則後果自負.】 Delphi7 Lite,簡約而不簡單,一次安裝,到處運行.內含4彈:Tiny/Mini/Meduim/Full,功能和體積由小至大,力求達到功能和體積的完美平衡.已作性能優化及優量精簡,含安裝/綠色便攜版二合一,集成了部分常用高效的IDE專家及外掛程式,致力於把Delphi7打造成一個現代化(相對而言)的整合式開發環境,使用本產品將使你在開發效率/使用體驗/系統相容性等方面上相對原版有大幅提高. 关键特性: 一次安裝,到處運行.第一次需安裝,以後每次只需註冊即可. 已安裝集成現在所有可用的升級補丁(至Delphi7 Update 1.1,IDE版本號為Build 8.1),集成目前絕大多數的Bug Fix Pack. 支援現在所有正在使用的Windows版本:Windows7, 2008 R2, Vista, XP, 2008, 2003, 2000, Me, 98, 和 NT 4.0,支援非管理員許可權使用者安裝,支援UAC. 特別地對Windows7提供全面支援. 去除了所有多餘的安裝選項但保留了原始程式碼選項,移除了非必需的檔(ModelMaker,InterBase,MergeModules,Extra Docs,Images,MDAC等). 採用安裝後動態編譯生成RTL,VCL的DCU檔,極大的減小了安裝檔體積. 可選將Delphi7 RTL/VCL替換為Delphi2007 的RTL/VCL,讓Delphi7支援Delphi2007新增的Vista屬性. 可選將Delphi7 RTL/VCL 恢復為使用官方原始的源碼檔,僅供用於部分協力廠商元件兼容性的可能需要(不推薦). 安裝程式是設計為可重複安裝的.您在安裝新版本時,如果安裝程式沒有特別指明,則不需要先刪除舊的版本,直接升級即可,所有設置都會保留,原Delphi安裝的控制項及設置等會自動導入新安裝IDE環境中. 安裝程式內置了可直接選擇的”綠色便攜版安裝模式”,使用此模式安裝後目的檔案夾即成為一個可移動的綠色版,實現徹底的名符其實的”安裝/綠色便攜版二合一”. 安裝程式自帶獨立的綠化註冊程式(D7LiteReg.exe),方便您快速地恢復Delphi7開發環境(控制項/專家/設置).直接複製整個Delphi目錄,再執行D7LiteReg.exe即可完成Delphi的註冊工作.同樣方法可適用于對其它Delphi7版本進行綠化註冊,如Delphi7 SECOND EDITION v7.2. 安裝程式支援”使用現有的原始程式碼重編譯安裝(僅覆蓋安裝時有效)”或”使用外部的Delphi7-source原始程式碼來編譯安裝”,更多詳情請查看說明. 安裝程式帶附加的命令列功能.支援對已安裝程式的功能表/註冊表/雜項進行修復,使用命令列參數/?或/help查看更多詳情. 安裝程式支援附加的命令列參數以實現額外功能.支援對已安裝Delphi7程式的功能表/註冊表/雜項進行修復,常用的命令列參數已直接集成到了安裝程式中,在視窗中點擊右鍵或使用命令列參數/?或/help查看更多詳情. 安裝程式會根據安裝目的機器性能自動選擇不同的安裝元件. 安裝程式支援多語言介面(含中文簡體/繁體/英文). 同時可選僅替換為Delphi2007中windows相關pas,以支援XP/Vista API及視窗屬性,不同于完全替換Delphi2007 RTL/VCL,能最大程度保持Delphi7的相容性的同時支援vista的新API及視窗屬性. 代碼編輯器顏色方案設為Delphi2006樣式. 包含程式設計專用字體Consolas (推薦字體大小為10並且啟用ClearType). IDE及VCL預設字體由原先的MS Sans Serif改為Tahoma,介面看上去更為美觀. 可選擇修改Delphi IDE本身支援XP風格,在設計時即可見到程式運行的XP效果,所見即所得. 集成DelphiZLib 1.2.5(ZLibEx.pas),可選擇升級內置的ZLib 1.04至ZLib 1.2.5. 集成VCL Fix Pack 1.4,需要在工程中手動引用單元VCLFixPack.pas. 集成Midas Speed Fix 1.2,需要在工程中手動引用單元MidasSpeedFix.pas. 集成以下來自www.delphi-jedi.org的擴展的Win32Api單元: SHELL LITE :: Microsoft Shell Lightweight Utility API, v.1.2/SNMP :: Microsoft headers for Simple Network Management Protocol definitions/WINSOCK 2 :: Winsock 2 API (Windows Sockets). 集成MySQL Driver for DBExpress,支援MySQL 3.22/4.0/4.1/5.0 驅動程式. 集成Newly Delphi Features Extented Components,移植自Delphi7以后版本新增的控制項,如Vista Dialogs等,讓Delphi7也可以開發Vista風格對話方塊的程式. 包含下列專家或工具(依據版本不同有所差異): Delphi IDE 外掛程式 DelphiSpeedUp 3.1.(IDE加速). Delphi IDE 外掛程式 DDevExtensions 2.3.(增強IDE中工程的設置及編譯,可為工程增加不同版本編譯配置如release/debug版). Delphi 專家 GExperts 1.34 Experimental.(超級IDE專家). Delphi 專家 DelforExp 2.5.(代碼格式化工具). Delphi 專家 UnitExpert(提高IDE單元操作效率工具). Delphi 專家 CnWizards 0.9.7.599.(由中國人開發的超級IDE專家,支援原始程式碼結構高亮連線顯示,能自動備份恢復已安裝控制項資訊,製作自己綠化版delphi的好工具). Delphi 工具 DelphiDistiller 1.85.(選擇IDE啟動時載入的控制項及設置工具). Spy工具Microsoft Spy++ v7.1和Spy4Win (Spy for Window) v0.20b. EXE/DLL依賴關係分析工具Dependency Walker 2.2. DLL匯出函數檢視器DLL Export Viewer v1.42. BDE (Borland Database Engine 5.2), 及相關工具BDE Administrator, SQL Explorer, Database Desktop, SQL Monitor, Data Pump等. BDE 示例資料庫(別名DBDEMOS).
Platform: | Size: 77731415 | Author: ygman@qq.com | Hits:

[matlabXMLlToolbox2

Description: The XML Toolbox converts MATLAB data types (such as double, char, struct, complex, sparse, logical) of any level of nesting to XML format and vice versa. For example, >> project.name = MyProject >> project.id = 1234 >> project.param.a = 3.1415 >> project.param.b = 42 becomes with str=xml_format(project, off ) "<project> <name>MyProject</name> <id>1234</id> <param> <a>3.1415</a> <b>42</b> </param> </project>" On the other hand, if an XML string XStr is given, this can be converted easily to a MATLAB data type or structure V with the command V=xml_parse(XStr).
Platform: | Size: 214016 | Author: leiming691128 | Hits:

[SQL Serverstudent

Description: 学生选修课程管理系统的设计与实现 目 录 一、需求分析 2 1.1系统简要分析 2 1.2 应用需求分析 2 二、概要设计 4 2.1业务流分析 4 2.2数据流分析 4 2.3程序数据流程分析及流程设计 4 2.4数据字典 7 2.5系统数据模型设计 8 2.5.1 E-R图 8 2.5.2数据库建表 9 三、详细设计 11 3.1登陆模块的设计与功能实现:界面设计如下: 11 3.2系统管理 11 3.2.1系统管理菜单 11 3.2.2用户管理窗口 12 3.3管理员操作 12 3.4学生信息界面设计与功能实现 13 3.5课程信息界面设计与功能的设计 17 3.6选课界面设计与功能实现 18 四、调试分析和小结 20 五、参考文献 23-Elective courses students Management System Design and Implementation of a directory, needs analysis 21.1 System 21.2 Application of a brief analysis of needs analysis 2, a summary of the design of 42.1 business 42.2 flow analysis data flow analysis data flow analysis procedure 42.3 and 42.4 process design data dictionary 72.5 System Data Model 82.5.2 Figure 82.5.1 ER design database built Table 9 Third, the detailed design of 113.1 landing module design and functions: interface design is as follows: 113.2 System Management System Management 113.2.1 menu window 113.2.2 user management operations 123.3 administrator 123.4 Student Information interface design and function of the realization of 133.5 information interface design curriculum design and function of 173.6 interface design and function of course to achieve 18 d, debugging analysis and summary of 20 V. References 23
Platform: | Size: 962560 | Author: xionglingyuan | Hits:

[SCMuCOS-II_Model_STM32

Description: IAR4.42版本的UCOSII for STM32移植模板-IAR4.42 version of UCOSII for STM32 transplantation template
Platform: | Size: 1319936 | Author: zt | Hits:

[Windows DevelopWindows_Driver_Programming_Tutorial

Description: 第一章 字符串 6 1.1 使用字符串结构 6 1.2 字符串的初始化 7 1.3 字符串的拷贝 8 1.4 字符串的连接 8 1.5 字符串的打印 9 第二章 内存与链表 11 2.1内存的分配与释放 11 2.2 使用LIST_ENTRY 12 2.3 使用长长整型数据 14 2.4使用自旋锁 15 第三章 文件操作 18 3.1 使用OBJECT_ATTRIBUTES 18 3.2 打开和关闭文件 18 3.3 文件的读写操作 21 第四章 操作注册表 25 4.1 注册键的打开操作 25 4.2 注册值的读 26 4.3 注册值的写 29 第五章 时间与定时器 30 5.1 获得当前滴答数 30 5.2 获得当前系统时间 31 5.3 使用定时器 32 第六章 内核线程 35 6.1 使用线程 35 6.2 在线程中睡眠 36 6.3 使用事件通知 37 第七章 驱动与设备 41 7.1 驱动入口与驱动对象 41 7.2 分发函数与卸载函数 41 7.3 设备与符号链接 42 7.4 设备的生成安全性限制 44 7.5 符号链接的用户相关性 46 第八章 处理请求 47 8.1 IRP与IO_STACK_LOCATION 47 8.2 打开与关闭的处理 48 8.3 应用层信息传入 49 8.4 驱动层信息传出 51 后记:我的闲言碎语 54 -Chapter 6 Strings 1.1 The structure of 6 string 1.2 initialization string 7 1.3 copy of the string 8 1.4 connection string 8 1.5 string printing 9 Chapter II memory and list 11 2.1 memory allocation and release of 11 2.2 Use LIST_ENTRY 12 2.3 The use of a long integer 14 2.4 The use of spin locks 15 Chapter 18 File Operation 3.1 Use OBJECT_ATTRIBUTES 18 3.2 to open and close the file 18 3.3 file read and write operations 21 Chapter IV Operation registry 25 4.1 registration key open operation 25 4.2 read 26 registered value 4.3 The value of the write register 29 Chapter V Time and Timer 30 5.1 to obtain the current number of 30 ticks 5.2 to obtain the current system time 31 5.3 using the timer 32 Chapter VI kernel thread 35 6.1 using threads 35 6.2 In the thread sleep 36 6.3 use the event notification 37 Chapter VII of the driver and equipment 41 7.1 Drive entrance and the driver object 41 7.2 Distribution Functions and unloading function, 41 7.3 Equipment
Platform: | Size: 70656 | Author: chenzifeng | Hits:

[Internet-Networkv42

Description: V.42 protocol description with sources
Platform: | Size: 19456 | Author: rdn | Hits:

[Communication-Mobilev42bis

Description: v.42 bis 协议,sndcp协议压缩标准。sndcp属于3gpp规范-v.42 bis agreement, sndcp protocol compression standard. sndcp are 3gpp specification
Platform: | Size: 251904 | Author: lixiaojun | Hits:

[Compress-Decompress algrithmsCCITTV_42bis--compression-algorithm

Description: 本文主要介绍CCITT v.42bis建议的压缩算法的主要特点,以及实现该算法的数据结构,形成新串的方法,动态维护字典的方法和指针编码,并给出V.42bis建立的模拟结果。V.42压缩可以用于SNDCP子层分组数据部分的压缩。-This paper describes the main features recommended by the CCITT v.42bis compression algorithm, and the data structure of the algorithm, to form a new string method, the dynamic maintenance of the dictionary and the pointer encoding, and gives the V.42bis established simulation results. V.42 compression can be used for part of the SNDCP sublayer packet data compression.
Platform: | Size: 358400 | Author: 曾秀姗 | Hits:

[GPS developMobile-station-GPRS-overall-design

Description: 本文档描述中兴移动台GPRS协议栈总体设计方案。在描述GPRS系统基本原理的基础上,提出中兴移动台GPRS协议栈的设计目标,并描述了协议栈的实现方案。-This document describes the ZTE mobile station GPRS protocol stack, the overall design. Describe the basic principle of the GPRS system on the basis of the design goals of the ZTE Mobile GPRS protocol stack, and describes the implementation of the protocol stack. established simulation results. V.42 compression can be used for part of the SNDCP sublayer packet data compression.
Platform: | Size: 692224 | Author: 曾秀姗 | Hits:

[Other Riddle gamesmj-1.6-src

Description: unix下的一个带客户端的麻将游戏 带源码-$Header: /home/jcb/newmj/RCS/README,v 11.4 2003/03/15 12:42:44 jcb Rel $ This is the README file for the Unix mah-jong programs by J. C. Bradfield. NOTICES: -------- Please see the file LICENCE for terms and conditions of these programs. Source distribution only: ------------------------- The code in the tiles-v1/ directory was not written by me see tiles-v1/README for information and licensing. The file MANIFEST contains a description of all the files you should find in this distribution. Binary distributions only: -------------------------- In the distribution directory, you will find the following files: mj-server the controller program. ( mj-server.exe in Windows ) mj-player a computer player. ( mj-player.exe in Windows ) xmj a graphical client. ( xmj.exe in Windows ) README this file LICENCE the licence rules.txt the rules as implemented by the programs use.txt documentation on how to use the programs CHANGE
Platform: | Size: 382976 | Author: 草原之火 | Hits:

[Linux-Unixnmclan_cs

Description: Linux PCMCIA ethernet adapter driver for the New Media Ethernet LAN. nmclan_cs.c,v 0.16 1995 07 01 06:42:17 rpao Exp rpao.
Platform: | Size: 12288 | Author: qsviuzue | Hits:

[Linux-Unixmdm_msg

Description: Fields in assign DLC information element for modem protocol V.42 MNP:.
Platform: | Size: 3072 | Author: kzkqfl | Hits:

[Linux-Unixschedule

Description: Id: schedule.h,v 1.5 2006 05 03 21:53:42 vanhu Exp.
Platform: | Size: 2048 | Author: qanmoubw | Hits:

[uCOSMicrium_Xilinx_Repo_1_42_

Description: ucos BSP can be use as the BSP v 1.42
Platform: | Size: 28528640 | Author: denisys | Hits:

[Com PortVB与OMRON PLC通讯源码

Description: 这是VB和欧姆龙通讯源码经典的例子, Lettura_Dm = False ricez_ok = -1: timeout = False trasm = "@00RD" trasm = trasm + Right$(Str$(10000 + dm!), 4) trasm = trasm + "0001" trasm = trasm + bcc(trasm) + Chr$(42) + Chr$(13) Omron!Comm1.Output = trasm conta = 0 Do conta = conta + 1 If conta > 1200 Then timeout = True: Exit Do Loop Until Omron!Comm1.InBufferCount >= 15 a = Omron!Comm1.Input If Not timeout Then fcs = Mid$(a, (Len(a) - 3), 2) trasm = Left$(a, (Len(a) - 4)) If fcs <> bcc(trasm) Then timeout = -1 Exit Function End If valore = Mid$(a, 8, 4) V = Val("&H" + valore) Lettura_Dm = True End If ricez_ok = 0 Omron!Comm1.InBufferCount = 0 End Function(This is a VB to omron Lettura_Dm = False ricez_ok = -1: timeout = False trasm = "@00RD" trasm = trasm + Right$(Str$(10000 + dm!), 4) trasm = trasm + "0001" trasm = trasm + bcc(trasm) + Chr$(42) + Chr$(13) Omron!Comm1.Output = trasm conta = 0 Do conta = conta + 1 If conta > 1200 Then timeout = True: Exit Do Loop Until Omron!Comm1.InBufferCount >= 15 a = Omron!Comm1.Input If Not timeout Then fcs = Mid$(a, (Len(a) - 3), 2) trasm = Left$(a, (Len(a) - 4)) If fcs <> bcc(trasm) Then timeout = -1 Exit Function End If valore = Mid$(a, 8, 4) V = Val("&H" + valore) Lettura_Dm = True End If ricez_ok = 0 Omron!Comm1.InBufferCount = 0 End Function)
Platform: | Size: 3072 | Author: 铭铭之中 | Hits:

CodeBus www.codebus.net