版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 以下小程序都在TC2.0中运行通过,程序没来得及加注释。程序比较简单,都是一些初学c语言时写的程序,请通过运行看效果。5个字符串排序.c#include stdio.h#include stdilb.hvoid paixu(char *p5) int i,j; char *q; for(i=0;i4;i+) for(j=0;j0) q=pj; pj=pj+1; pj+1=q; main() char *p5; int i; for(i=0;i5;i+) pi=(char *)malloc(10); scanf(%s,pi); paixu(p); for(i=0;i1|take4|take-G
2、ame Begin-n);stick(21);printf(-Game Over!-n);&/猜数字游戏#include stdio.h#include stdlib.hint yuan4,shu4;yuan_fen(int num)yuan0=num/1000;yuan1=num/100%10;yuan2=num/10%10;yuan3=num%10;shu_fen(int num)shu0=num/1000;shu1=num/100%10;shu2=num/10%10;shu3=num%10;int shudui_panduan()int shu14,shudui=0,i,j,t=0,q,
3、biao=0;for(i=0;i4;i+) shu1i=-1;for(i=0;i4;i+)for(j=0;j4;j+)if(shui=yuanj)biao=0;for(q=0;qt;q+)if(shui=shu1q) biao=1;break;if(biao=0)shu1t=shui;t+;shudui+;return shudui;int weidui_panduan()int weidui=0,i;for(i=0;i9999|manin1000) goto g1;shu_fen(manin);gotoxy(23,6+dui);printf(%d,shudui_panduan();gotox
4、y(40,6+dui);printf(%d,weidui_panduan();if(weidui_panduan()!=4) dui+;goto g1;else break;gotoxy(10,7+dui);printf(yi gong cai le %d ci!,dui+1);gotoxy(10,8+dui);printf(ni xuan ze ji xu?(y/n);flushall();if(getchar()=y) goto g2;&/九宫格.c main() int a,b, c, d,i,j; int s3030 ;/* 定义一个足够大的数组*/ printf(shu ru yi
5、ge ji shu:); scanf(%d,&b); if(b%2!=0)/*输入一个数,不是偶数才执行下面的代码*/ for ( i = 0; i b; i+)/*将数组里赋初值0,以便后面的比较*/for ( j = 0; j b; j+)sij = 0;d = (b - 1) / 2;c = 0; /*下面是向数组里填数,填成魔方*/s0d = 1;for (a = 2; a = 0)if (d + 1 b - 1)c = c - 1;d = 0;elseif (sc - 1 d + 1 != 0)c = c + 1;elsec = c - 1;d = d + 1;elseif (d +
6、 1 b - 1)c = c + 1;elsec = b - 1;d = d + 1;sc d = a;/*下面输出数组*/for (i = 0; i b; i+) for (j = 0; j b; j+)printf(%dt,sij);/*这里用了t所以不要输入的数太大,不然输出对不齐*/printf(n);&/输出菱形 数组.c#include #include main() int i,j,n; char s20=; printf(nn); n=19; for(i=-n/2; i=n/2; i+) for(j=0;j=abs(i); j+)printf(%c, ); for(j=0;j=
7、n/2-abs(i);j+)printf(%c,sj); for(j=19-(n/2-abs(i); j2|inmanthisman) gotoxy(15,20);printf(Input error!Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );goto l1;this_inrets() l2:gotoxy(20,17);printf( ); gotoxy(20,17);printf(Input the number of retainer to that bank:);flushall();i
8、f(scanf(%d,&inret)!=1)goto l2;gotoxy(15,20);printf( );if(inret2|inretthisret) gotoxy(15,20);printf(Input error!Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );goto l2;that_inmans() l3:gotoxy(20,17);printf( );gotoxy(20,17);printf(Input the number of men to this bank:);flushall
9、();if(scanf(%d,&inman)!=1)goto l3;gotoxy(15,20);printf( );if(inman2|inmanthatman)gotoxy(15,20);printf(Input error!Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );goto l3;that_inrets() l4:gotoxy(20,17);printf( );gotoxy(20,17);printf(Input the number of retainer to this bank:);
10、flushall();if(scanf(%d,&inret)!=1)goto l4;gotoxy(15,20);printf( );if(inret2|inretthatret)gotoxy(15,20);printf(Input error!Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );goto l4;int this_panduan()int thisman1,thisret1,thatman1,thatret1;thisman1=thisman;thisret1=thisret;thatma
11、n1=thatman;thatret1=thatret;thisman=thisman-inman;thisret=thisret-inret;thatman=thatman+inman;thatret=thatret+inret;if(thisman!=0&thismanthisret) thisman=thisman1; thisret=thisret1; thatman=thatman1; thatret=thatret1;return 0;elseif(thatman!=0&thatmanthatret)thisman=thisman1;thisret=thisret1;thatman
12、=thatman1;thatret=thatret1;return 0;else return 1;int that_panduan()int thisman1,thisret1,thatman1,thatret1;thisman1=thisman;thisret1=thisret;thatman1=thatman;thatret1=thatret;thisman=thisman+inman;thisret=thisret+inret;thatman=thatman-inman;thatret=thatret-inret;if(thisman!=0&thismanthisret) thisma
13、n=thisman1; thisret=thisret1; thatman=thatman1; thatret=thatret1;return 0;elseif(thatman!=0&thatmanthatret)thisman=thisman1;thisret=thisret1;thatman=thatman1;thatret=thatret1;return 0;else return 1;t_printf()int i;gotoxy(12,15);printf( );gotoxy(12,15); for(i=0;ithisman;i+) printf(Man );gotoxy(12,16)
14、;printf( );gotoxy(12,16); for(i=0;ithisret;i+) printf(Retainer );gotoxy(42,15);printf( );gotoxy(42,15); for(i=0;ithatman;i+) printf(Man );gotoxy(42,16);printf( );gotoxy(42,16); for(i=0;i);if(thisman!=0) this_inmans();else inman=0;if(thisret!=0&inman!=2) this_inrets();else inret=0;if(inret+inman2)got
15、oxy(15,20);printf(Input error!Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );goto t1;if(this_panduan()!=1) gotoxy(15,20);printf( );gotoxy(15,20);printf(The man were killed.Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );j=1;break;t_printf();t2:if(this
16、man=0&thisret=0) break; gotoxy(27,14);printf(2)gotoxy(15,20);printf( );gotoxy(15,20);printf(Input error!Press any key to restart.);goto t2;if(that_panduan()!=1) gotoxy(15,20);printf( );gotoxy(15,20);printf(The man were killed.Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );j=
17、1;break;t_printf();if(j=1) goto w1;elsegotoxy(15,20);printf( );gotoxy(15,20);printf(Congratulations! Mission Completed!Any key to quit.);flushall();getchar();return 0;&字符倒置 删除.C#include char *fan(char *p)char *a,*d,b;a=p;d=p;while(*p!=0)p+;p-;for(;adataq-data) if(p-lchild=NULL) p-lchild=q;elseadd(p-
18、lchild,q);else if(p-rchild=NULL)p-rchild=q;elseadd(p-rchild,q);bianli( struct ercha *p)if(p!=NULL)bianli(p-lchild);printf(t%d,p-data);bianli(p-rchild);main()int pr_num,i=0;struct ercha *p;while(1)g1:flushall();p=(struct ercha *)malloc(LEN);if(scanf(%d,&pr_num)!=1) goto g1;if(pr_num=-1111) break;p-da
19、ta=pr_num;p-lchild=NULL;p-rchild=NULL;if(i=0) head=p;i+;continue;add(head,p);bianli(head);$二叉树.c#include stdio.h#include conio.h#include malloc.h#define LEN sizeof(struct ercha)#define NULL 0struct ercha *head;struct ercha char data; struct ercha * rch; struct ercha * lch;qianbianli(struct ercha *p)
20、 if(p!=NULL) printf(%c ,p-data); qianbianli(p-lch); qianbianli(p-rch); zhongbianli(struct ercha *p) if(p!=NULL) zhongbianli(p-lch); printf(%c ,p-data); zhongbianli(p-rch); houbianli(struct ercha *p) if(p!=NULL) houbianli(p-lch); houbianli(p-rch); printf(%c ,p-data); charu() char c,b; struct ercha *p
21、,*q;while(1) p=(struct ercha *)malloc(LEN); printf(shu ru shu ju:n); flushall(); scanf(%c,&c); p-data=c; p-rch=NULL; p-lch=NULL; if(c=0) break; if(head=NULL) head=p; else q=head; do printf(xuan ze cha ru wei zhi:n); flushall(); scanf(%c,&b); switch(b) case r: if(q-rch!=NULL) q=q-rch;printf(yi you shu ju,qing zai ci ); else q-rch=p
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 职业化培训题目及答案
- AI在心理咨询中的应用
- 医疗器械经营许可证管理制度
- 博士后科研工作站建站资助申领表
- 6.2.2 亚洲的人文环境与地域差异(教学课件)-初中地理中图版
- 质量部月报总结
- 2026年北师大版(新教材)小学数学一年级下册期末学情测试卷及答案
- 网络信息安全基础(AIGC版)随堂前测练习题及参考答案 项目2-任务1-前测练习-单选题5
- 2026阜阳燃气面试题目及答案
- 2026摆摊手工艺面试题及答案
- 小数的加减法(教案)-三年级下册数学青岛版
- 立杆施工方案
- 六年级下册科学全册精编知识点(新改版苏教版)
- 土地征收培训课件
- 生产安全事故应急管理中的问题剖析
- GB/T 43021-2023电子组装件焊接的返工、改装和返修工艺要求
- vicruns vd35变频器参数说明书
- 附合导线测角、测距记录表
- 浙江省嘉兴市高二下学期期末数学试题(原卷版)
- GB/T 10655-2003高聚物多孔弹性材料空气透气率的测定
- GB 20052-2006三相配电变压器能效限定值及节能评价值
评论
0/150
提交评论