c语言有啥简单的小程序,c语言-简单小程序-简单算法

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

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|takeGame Beginn);stick(21);printf(Game Over!n);&/猜数字游戏#include stdio.h#include stdlib.h。

2、int 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; else if (sc - 1 d + 1。

3、 != 0) c = c + 1; else c = 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=1234567890987654321;printf(nn);n=19;for(i=-n/2; i2|inmanthisman) gotoxy(15,20);printf(Input error!Press any key to restart.);flushal。

4、l();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();if(scanf(%d,&inret)!=1)goto l2; gotoxy(15,20); printf( ); if(inret2|inretthisret) gotoxy(15,20);printf(Input error!Press any key to 。

5、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();if(scanf(%d,&inman)!=1)goto l3; gotoxy(15,20); printf( ); if(inman2|inmanthatman)gotoxy(15,20);printf(Input error!Press 。

6、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:); flushall();if(scanf(%d,&inret)!=1)goto l4; gotoxy(15,20); printf( ); if(inret2|inretthatret)gotoxy(15,20);printf(In。

7、put 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;thatman1=thatman;thatret1=thatret;thisman=thisman-inman;thisret=thisret-inret;thatman=thatman+inman;thatret=thatret+in。

8、ret; if(thisman!=0&thisman); if(thisman!=0) this_inmans();else 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( 。

9、); 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(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_。

10、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();if(j=1) goto w1;elsegotoxy(15,20);printf( ); gotoxy(15,20);printf(Congratulations! Mission Completed!Any key to quit.); flus。

11、hall();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-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-dat。

12、a); 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-data=pr_num;p-lchild=NULL;p-rchild=NULL;if(i=0) head=p;i+;continue; add(head,p);bianli(head);$dddddddddddddddd*$二叉树 .c#include st。

13、dio.h#include conio.h#include malloc.h#define LEN sizeof(struct ercha)#define NULL 0struct ercha *head;struct erchachar 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)。

14、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,*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=N。

15、ULL;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: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 。

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值