Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - v c
Search - v c - List

/*
实现效果:
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列的

 


Date : 2008-05-05 Size : 4.29kb User : good@588

DL : 0
*** *维吉利亚密码C语言版*************简单实用-*******维吉利亚password************* C language version of simple and practical
Date : 2025-12-30 Size : 1kb User :

免费的Office控件,可以应用于B/S和C/S程序,实现完美内嵌office-Office free of charge controls, can be applied to B/S and C/S procedures, to achieve the perfect embedded office
Date : 2025-12-30 Size : 116kb User : 黄河岸

DL : 0
VCL组件的库包BPL文件(Borland Package Library)是否能够向ActiveX一样, 在脱离任何辅助文件的情况下使用?也就是在没有相关的.h、.bpi和.lib等文 件的支持下,是否也能使用,答案是肯定的,甚至是不在IDE中也能够载入bpl 并创建其中的对象和使用之,作个简单的试验便知道,编制一个包含任意用户 组件的bpl,然后复制到另一个与之无关的C++ Builder环境中,IDE能够载入, 并且能够创建设计时对象,修改属性,但是程序不能编译通过,因为编译器需 要关于组件的预定义头文件。因此可以肯定bpl文件本身是完整的,它包含了所 有运行时需要的信息。
Date : 2025-12-30 Size : 136kb User : 吴松

MPLAB C30 Compiller v 3_02
Date : 2025-12-30 Size : 27.78mb User : Sudmarina

K Means Algrithm it is in v c#.
Date : 2025-12-30 Size : 10kb User : Naeem Ullah

DL : 0
是C++编写的实现计算器大部分功能的一个小程序,本程序能在v c++上正确编译运行-Is written in C++ to achieve most of the functions of a small calculator program, this program can v c++ compiler to run correctly on
Date : 2025-12-30 Size : 194kb User : 王伟

链路状态路由算法实现。链路状态算法又叫最短路径优先SPF(Short Path First)算法。按照SPF的要求,路由器中路由表依赖于一张能表示整个个网络拓扑结构的无向图G(V,E)。-Link state routing algorithm. Link State algorithm called the shortest path first SPF (Short Path First) algorithm. In accordance with the requirements of SPF, the router relies on a routing table can be said that the entire network topology undirected graph G (V, E).
Date : 2025-12-30 Size : 2kb User : yiyi

Johson算法是目前最高效的在无负环可带负权重的网络中求所有点对最短路径的算法. Johson算法是Bellman-Ford算法, Reweighting(重赋权重)和Dijkstra算法的大综合. 对每个顶点运用Dijkstra算法的时间开销决定了Johnson算法的时间开销. 每次Dijkstra算法(d堆PFS实现)的时间开销是O( E * lgd(V) ). 其中E为边数, V为顶点数, d为采用d路堆实现优先队列ADT. 所以, 此种情况下Johnson算法的时间复杂度是O( V * E * lgd(V) ).-The Johson algorithm is currently the most efficient of the network without negative ring can with negative weights seek all points of the shortest path algorithm. Johson algorithm Bellman-Ford algorithm Reweighting (re-empower the weight) and Dijkstra algorithm for the large integrated. For eachtime overhead of the vertices using Dijkstra algorithm to determine the time of the Johnson algorithm overhead each Dijkstra algorithm (d-heap PFS), time overhead is O (E* lgd (V)) where E is the number of edges, V verticesd d Lu heap priority queue the ADT. this case the Johnson algorithm time complexity is O (V* E* lgd (V)).
Date : 2025-12-30 Size : 3kb User : wwll

DL : 0
推箱子 c++ v c++ 6.0-Sokoban c++ vc++ vc++ 6.0
Date : 2025-12-30 Size : 1.42mb User : 金锡平

Kerlinhan-Lin VLSI bi-partition 算法。 C++程序,一个cpp,一个.h. Kerlinhan-lin是二分图的最小权值算法,经常使用在VLSI电路自动化设计的物理paratition上,在其他的图形问题中也有应用。-Kerlinhan-Lin bi-partitioning algorithm. Mainly used for VLSI CAD design
Date : 2025-12-30 Size : 16kb User : Yuheng

DL : 0
C语言程控交换机源代码, C语言程控交换机源代码, C语言程控交换机源代码,-Cbh adnbjh nbejewq w3er erfr ewr w3r4 234yg 3h 5jn7 45 2q3f v yn wcd gb45 vw2 r4324g 5h 2 g g4ebh ew r tg tr g es f e t t wr tgry ry ret
Date : 2025-12-30 Size : 2.14mb User : 许文涛

界面操作,更好看不好看不好看hi高考,感觉GV就V据监控v(user interface operation)
Date : 2025-12-30 Size : 7kb User : 野朝2016

//PIC单片机滚动码解码C程序 // Interrupt based receive routine 基于中断的接收例程 // Compiled using HiTech PIC C compiler v.7.93 编译使用该PIC的C编译器v.7.93 #define CLOCK 4 // MHz #define TE 400 // us #define OVERSAMPLING 3 // #define PERIOD //TE/OVERSAMPLING*4/CLOCK #define NBIT 65 // number of bit to receive -1(HCS300 66-1=65)(Interrupt based receive routine)
Date : 2025-12-30 Size : 5kb User : jihh04

DL : 0
REPLACE THE C IN COLUMN 1 C*** WITH A BLANK AND ON THE CARDS IDENTIFIED AS FORTRAN-V C*** REPLACE THE BLANK IS COLUMN 1 WITH A C.
Date : 2025-12-30 Size : 24kb User : l454216@mvrht.net

lmdlsamvd.fgdsbds v,c.x,bc;,bsd.,b;l,gsd(vfdbfdnfdbwqehfngfkjfghnfbv)
Date : 2025-12-30 Size : 469kb User :

MT5 API 交易员程序示例程序,VC++代码(MetaTrader 5 Manager API dealer example code, V C++ code)
Date : 2025-12-30 Size : 49.52mb User : 关键

V.C. Chen M. Martorella新出的ISAR成像书籍《 Inverse Synthet Aperture Radar》中示例的源程序(V.C. Chen M. Martorella new ISAR imaging book "Inverse Synthet Aperture Radar" example of the source)
Date : 2025-12-30 Size : 30.6mb User : 小李花花

学习Microsoft VC#的经典教材。(Totorial to learn VC#)
Date : 2025-12-30 Size : 4.33mb User : ymzl99

DL : 0
V c++ 静 态 分 割 窗 口的易学例子()
Date : 2025-12-30 Size : 27kb User : enclosacg
« 12 3 4 »
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.