c语言简单小程序说明功能,c语言-简单小程序-简单算法

《c语言-简单小程序-简单算法》由会员分享,可在线阅读,更多相关《c语言-简单小程序-简单算法(20页珍藏版)》请在人人文库网上搜索。

1、以下小程序都在TC2.0中运行通过,程序没来得及加注释。程序比较简单,都是一些初学c语言时写的程序,请通过运行看效果。5个字符串排序.c#include stdio.h#include stdilb.hvoid paixu(char *p5)int i,j;char *q;for(i=0;i0)q=pj;pj=pj+1;pj+1=q;main()char *p5;int i;for(i=0;i1|take4|take-Game Begin-n);stick(21);printf(-Game Over!-n);&/猜数字游戏#include stdio.h#include stdlib.hint。

2、 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,biao=0;for(i=0;i9999|manin= 0)if (d + 1 b - 1)c = c - 1;d = 0;elseif (sc - 1 d + 1 != 0)。

3、c = c + 1;elsec = c - 1;d = d + 1;elseif (d + 1 b - 1)c = c + 1;elsec = b - 1;d = d + 1;sc d = a;/*下面输出数组*/for (i = 0; i #include main()int i,j,n;char s20=;printf(nn);n=19;for(i=-n/2; i2|inmanthisman)gotoxy(15,20);printf(Input error!Press any key to restart.);flushall();getchar();gotoxy(15,20);print。

4、f( );goto l1;this_inrets()l2:gotoxy(20,17);printf( ); gotoxy(20,17);printf(Input the number of retainer to that bank:);flushall();if(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,2。

5、0);printf( );goto l2;that_inmans()l3:gotoxy(20,17);printf( );gotoxy(20,17);printf(Input the number of men to this bank:);flushall();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。

6、,20);printf( );goto l3;that_inrets()l4:gotoxy(20,17);printf( );gotoxy(20,17);printf(Input the number of retainer to this bank:);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();go。

7、toxy(15,20);printf( );goto l4;int this_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&thisman);if(thisman!=0) this_inmans();else。

8、 inman=0;if(thisret!=0&inman!=2) this_inrets();else inret=0;if(inret+inman2)gotoxy(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。

9、.);flushall();getchar();gotoxy(15,20);printf( );j=1;break;t_printf();t2:if(thisman=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 kil。

10、led.Press any key to restart.);flushall();getchar();gotoxy(15,20);printf( );j=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。

11、=p;while(*p!=0)p+;p-;for(;adataq-data) if(p-lchild=NULL) p-lchild=q;elseadd(p-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 er。

12、cha *)malloc(LEN);if(scanf(%d,&pr_num)!=1) goto g1;if(pr_num=-1111) break;p-data=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。

13、char data;struct ercha * rch;struct ercha * lch;qianbianli(struct ercha *p)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。

14、(p-rch);printf(%c ,p-data);charu()char c,b;struct ercha *p,*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;elseq=head;doprintf(xuan ze cha ru wei zhi:n);flushall();scanf(%c,&b);switch(b)case r: 。

15、if(q-rch!=NULL) q=q-rch;printf(yi you shu ju,qing zai ci );else q-rch=p;printf(cha ru cheng gong,qing zai ci );break; case l: if(q-lch!=NULL) q=q-lch;printf(yi you shu ju,qing zai ci );else q-lch=p;printf(cha ru cheng gong,qing zai ci );break;default:printf(shu ru you wu,qing chong xin );if(q-rch=p|。

16、q-lch=p) break;while(1);main() struct ercha *q;char c;while(1)printf(*n);printf(1 cha ru:n);printf(2 bianli:n);printf(*n);printf(you chose:n);flushall();scanf(%c,&c);switch(c)case 1:charu();break;case 2:printf(*n);printf(qian xu:n);qianbianli(head);printf(n*n);printf(zhong xu:n);zhongbianli(head);printf(n*n);printf(hou xu:n);houbianli(head);printf(n*n);break;printf(ni xian zai xiang ji xu ma?(y/n)n);flushall();scanf(%c,&c);if(c!=y)break。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值