Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - main.c
Search - main.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

实验一:C++编程入门 1. 设计一个程序,其中实现两个函数,分别要求: 1. 解一元二次方程 求解一元二次方程Ax²+Bx+C=0的根。用户输入A、B、C的值,输出方程根x1和x2。(使用引用) 2. 求三角形面积 输入三角形的三边长a、b、c(边长可以是小数),求三角形面积area,并输出。如果输入的三边构不成三角形,应给出“data error”的信息提示。注:根据“海伦”公式,area*area=p(p-a)(p-b)(p-c),其中p=(a+b+c)/2。 2. 设计一个控制台程序,输入一个数组(长度不超过100)的值,求出各个值从小到大排序后的次序。 输入:输入的第一个数为数组的长度,后面的数为数组中的值,以空格分割; 输出:各输入的值按从小到大排列的次序号。 Sample Input: 4 -3 75 12 -3 Output: -3 -3 4 12 75 3. 设计一个学生类,管理以下信息:学号、姓名、出生日期(包括年月日)、性别、班级、成绩。该类有2个方法:readInfo用于读取其信息,disPlay用于打印信息。编写main函数测试这个学生类,要求输入并打印5个学生信息。 三、实验要求  将程序源代码压缩后提交至学院FTP上对应实验和班级的目录中。  作业命名方式为:“学号姓名.rar”。  作业提交时间:下次实验课前提交。
Date : 2011-08-18 Size : 7.2kb User : zhuchao0731@163.com

实验三:C++编程入门 一、实验内容 1. 类模版。 2. 运算符重载。 3. 友元。 4. 继承。 二、实验题目 1, 设计一个类SavingsAccount,定义一个静态数据成员记录存款的年利率(rate),该类的每个成员都包含一个私有的数据成员balance,表示该成员当前的存款数额。提供一个成员函数CalMonthlyInterest(),用以计算月利息(用balance乘以rate再除以12),并将这个月利息加入balance中。提供一个静态成员函数ModifyRate(),用以改变静态数据成员rate的值。定义两个不同的SavingsAccount对象saver1和saver2,当前存款数额balance分别为2000.00和3000.00。首先将rate设置为3%,计算每个存款人的月息并打印新的结果,然后将rate设置为4%,再次计算每个存款人的月息并打印新的结果。 2, 设计一个学生类student,包括学生学号、姓名、成绩;设计一个友元函数,比较某两个学生成绩的高低;读入一个文本文件(格式如示例studengt.txt,每行的学号、姓名、成绩之间用四个空格隔开)中所有学生的学号、姓名、成绩,输出最高成绩和最低成绩的学生信息(学号、姓名、成绩)。 3, 阅读下面例子,将题中的Time类声明为Data类的友元类,通过Time类中的display函数引用Data类的私有数据,输出年、月、日和时、分、秒。 #include <iostream> using namespace std; class Date; //对Date类的提前引用声明 class Time //定义Time类 { public: Time(int,int,int); void display(Date &); //display是成员函数,形参是Date类对象的引用 private: int hour; int minute; int sec; }; class Date //声明Date类 { public: Date(int,int,int); friend void Time∷display(Date &); //声明Time中的display函数为友元成员函数 private: int month; int day; int year; }; Time∷Time(int h,int m,int s) //类Time的构造函数 { hour=h; minute=m; sec=s; } void Time∷display(Date &d) //display的作用是输出年、月、日和时、分、秒 { cout<<d.month<<″/″<<d.day<<″/″<<d.year<<endl; //引用Date类对象中的私有数据 cout<<hour<<″:″<<minute<<″:″<<sec<<endl; //引用本类对象中的私有数据 } Date∷Date(int m,int d,int y) //类Date的构造函数 { month=m; day=d; year=y; } int main( ) { Time t1(10,13,56); //定义Time类对象t1 Date d1(12,25,2004); //定义Date类对象d1 t1.display(d1); //调用t1中的display函数,实参是Date类对象d1 return 0; } 4, 将下面程序改为在类模板外定义各成员函数: #include <iostream> using namespace std; template<class numtype> //定义类模板 class Compare { public: Compare(numtype a,numtype b) { x=a;y=b; } numtype max( ) { return (x>y)?x:y; } numtype min( ) { return (x<y)?x:y; } private: numtype x,y; }; int main( ) { Compare<int> cmp1(3,7); //定义对象cmp1,用于两个整数的比较 cout<<cmp1.max( )<<″ is the Maximum of two integer numbers.″<<endl; cout<<cmp1.min( )<<″ is the Minimum of two integer numbers.″<<endl<<endl; Compare<float> cmp2(45.78,93.6); //定义对象cmp2,用于两个浮点数的比较 cout<<cmp2.max( )<<″ is the Maximum of two float numbers.″<<endl; cout<<cmp2.min( )<<″ is the Minimum of two float numbers.″<<endl<<endl; Compare<char> cmp3(′a′,′A′); //定义对象cmp3,用于两个字符的比较 cout<<cmp3.max( )<<″ is the Maximum of two characters.″<<endl; cout<<cmp3.min( )<<″ is the Minimum of two characters.″<<endl; return 0; } 5, 有两个矩阵a和b,均为2行3列,求两个矩阵的和。重载运算符“+”使之用于矩阵相加。如:c=a+b。重载插入运算符“<<”和流提取运算符“>>”,使之能用于该矩阵的输入和输出。 6, 利用类继承分别完成一个学生类、一个大学生类、一个本科生类,本科生类中包括了一个学生作为他的班长。在创建一个本科生对象时赋予他的全部信息,输出该本科生对象的全部信息。 7, 利用c++继承、多态虚函数、构造函数完成以下程序:设计人、老师、学生、大学生、研究生、大四学生等类、其主要属性自己定义,要求包括以下方法: 1) 构造函数,创建对象的主要信息 2) Display,显示每种类对象的主要信息 此外,要求每个类包含一个生日对象,其类型为Birthday类,学生类应该包含一个班主任对象,其类型为老师类。 三、实验要求  将程序源代码压缩后提交至学院FTP上对应实验和班级的目录中。  作业命名方式为:“学号姓名.rar”。  作业提交时间:下次实验课前提交。
Date : 2011-08-18 Size : 1.2mb User : zhuchao0731@163.com

DL : 0
矩阵求逆,经典算法,全主元高斯约当法,经典源码,用途广泛-matrix inversion, classic algorithms, the main yuan Gaussian all about when France, classic source, a wide range of uses
Date : 2025-12-19 Size : 165kb User : 李保磊

Delaunay三角网作为一种主要的DTM表尔法,具有权其广泛的用途。经过二十多年来的研究,它的生成算法巳趋于成熟。本文简要介绍了Delaunay三角网的定又及其特性,在简单回顾和评价了分割—归并法,逐点插入法,三角冈生长法等三类主沈算法的基础上,提出了一个融以上算法优点于一体,兼顾空间与时间性能的合成算法。经测试,一般情况下它的运算速度远快于逐点插入法,与分割—归并法相当,较好的情况下快于分割—归并法。-Delaunay Triangulation as a major DTM Fall table, with the right to its extensive use. After 20 years of study, which had been generating algorithm is maturing. This paper introduces a Delaunay Triangulation and another set of characteristics, in a brief review and evaluation of the divide-conquer method, point by point insertion method, the supraspinatus Growth Triangle law Shen three main algorithm on the basis of the above algorithm into an advantage in that balanced space and time performance of synthesis algorithm. After tests, under normal circumstances it's computational speed much faster than the insertion point by point, and the divide-conquer method rather, a better situation faster than divide-conquer method.
Date : 2025-12-19 Size : 3.66mb User : 苏聪

飞机航班定票系统 主要功能:航班信息录入(同时此模块可添加航班信息) 航班信息浏览 航班信息查询 办理顾客定票业务 办理顾客退票业务 -flights scheduled counting system main functions : flight information into (this module can also add flights) flights View flight information inquiries for business customers to book tickets for a refund business customers
Date : 2025-12-19 Size : 16kb User : 张亮

DL : 0
实现多人聊天,一人做服务器,其它人做客户端,主要用到winsocket连接机制.-achieve more than chat, a person servers, other people to do the client, the main mechanism used winsocket link.
Date : 2025-12-19 Size : 6kb User : 阿焦

DL : 0
读取dst文件(绣花文件类型)并绘出图形。 内容包括,以3字节一字符串组读取,并以dst文件读写方法进行换算,主要是直接读取每字节里的每1位进行计算,计算出x位移和y位移,然后换成屏幕画线需要的结束点,然后2点画线,再次循环则将上次的结束点赋给起始点,再次读取3字节进行计算。。。。 可重用代码:读取地址进行每字节的每1位的计算。 PS:dst文件可以用田岛软件进行编写。-read dst (embroidery file types) and draws graphics. The contents include, for a three-byte string group read, and to read and write documents dst conversion method, main is a direct read every byte of every Lane a calculated, the calculated displacement x and y displacement, screen painting then changed to the end line, then two dotted line again last cycle will end points assigned to the threshold, 3 byte read again calculated. . . . Reusable code : read addresses every byte of every one of calculation. PS : dst document TAJIMA software can be used for the preparation.
Date : 2025-12-19 Size : 38kb User : 阿长期

DL : 0
这是我的课程设计 由于时间有限,程序难免有不足。 还请多多指教。 程序建议不要在win2000和win xp的cmd下运行。 推荐在win98或纯dos中装有UCDOS中文DOS平台下运行。 主菜单程序为main.c 运行此程序,选择相应的菜单,即可运行查看到其他程序。 wnl.c万年历 adstd.c 学生数据库 ply.c小蜜蜂(UFO)游戏 tlife 生存模拟 但是要求main.c和其他程序的执行文件必须在同一目录里(文件夹)。否则连接其他程序将失败。 建议直接运行我已经编译好的执行文件(在ok目录下)运行main.exe即可通过菜单对四个程序进行调用。 如果发现不能正常使用本程序,请与我联系。 寝室电话:0732-8370551 7324474 QQ176141729 email:coynnbai@163.com 学生:陈欢 班级:03级计算机6班-This my course design due to the limited time available, it is inevitable that inadequate procedures. Also invited exhibitions. Procedures not recommended in WIN2000 and win xp running under the cmd. Suggest in win98 or pure dos installed with a Chinese UCDOS DOS platforms. The main menu main.c operating procedures for this process, the corresponding menu choice can look to other operating procedures. Wnl.c hefty almanac adstd.c student database ply.c Bee (UFO) tlife survival simulation games but main.c requirements and other procedures to be implemented in the same document directory (folder). Otherwise connected to other procedures will fail. A direct operation I have compiled implementation document (ok directory) main.exe can run through a menu of four procedure calls. If found to b
Date : 2025-12-19 Size : 77kb User : 陈欢

DL : 0
龟兔赛跑 一个学习c语言的例程,我按照一本经典c教程算法编写,演示了龟兔赛跑的过程,结果是随机出来的。很有趣味性-龟兔赛跑a learning c language routines, and I in accordance with a classical algorithm c tutorial prepared to demonstrate the process of龟兔赛跑The result is a random out. Very interesting
Date : 2025-12-19 Size : 1kb User : 张欢

DL : 0
利用c语言实现28位的crc校验,并测试其性能。-Using c language 28 crc check and test its performance.
Date : 2025-12-19 Size : 4kb User : 刘斌

DL : 0
Alternate, standalone main() file. Demonstrates linking to the startup code without having to link to any of the Turbo C library routines.-Alternate, standalone main() file. Demonstrates linking to the startup code without having to link to any of the Turbo C library routines.
Date : 2025-12-19 Size : 1kb User : HNSJB

DL : 0
统计字母的使用频率画统计图用c语言实现统计字母的使用频率画统计图用c语言实现-how often the characters be used,pointers
Date : 2025-12-19 Size : 1kb User : tyhser

DL : 0
The main C++ program for Rtrees
Date : 2025-12-19 Size : 2kb User : Jafat

DL : 0
本次课程设计的题目是:程序源代码的相似性。 对于两个C++语言的源程序代码,用哈希表的方法分别统计两个程序中使用C++语言关键字的情况,并最终按定量的计算结果,得出两份程序的相似性。 基本要求:建立C++语言关键字的哈希表,统计在每个源程序中C++关键字出现的频度, 得到两个向量X1和X2,通过计算向量X1和X2的相对距离来判断两个源程序的相似性。(Similarity detection procedures for (Similarity detection procedures for))
Date : 2025-12-19 Size : 1kb User : 咖啡犬瘟热

DL : 0
c语言基础,复习资料,以及头文件书写的方式和主程序的书写(C language foundation, review materials, and writing of header files and main programs)
Date : 2025-12-19 Size : 9kb User : heartz

DL : 0
C++ language max min ant system
Date : 2025-12-19 Size : 2kb User : bob13579

Object-C基础教程,适合于刚入门的程序员学习使用,涵盖了OC开发的主要技术(Object-C basic tutorials, suitable for beginners to learn and use, cover the main technologies of OC development)
Date : 2025-12-19 Size : 22.61mb User : 小白林

The #include <stdio.h> is a preprocessor command. This command tells compiler to include the contents of stdio.h (standard input and output) file in the program. The stdio.h file contains functions such as scanf() and print() to take input and display output respectively. If you use printf() function without writing #include <stdio.h>, the program will not be compiled. The execution of a C program starts from the main() function. The printf() is a library function to send formatted output to the screen. In this program, the printf() displays Hello, World! text on the screen. The return 0; statement is the "Exit status" of the program. In simple terms, program ends with this statement.
Date : 2025-12-19 Size : 17kb User : knidra

DL : 0
CF d3d 无检测人物透视C源码,Z轴!(CF D3D non - detection of human perspective C source, Z axis!)
Date : 2025-12-19 Size : 1kb User : 职业杀手
« 12 3 4 5 6 7 8 9 10 ... 22 »
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.