c语言-简单小程序-简单算法.doc

c语言-简单小程序-简单算法.doc

ID:56277755

大小:59.00 KB

页数:20页

时间:2020-06-05

c语言-简单小程序-简单算法.doc_第1页
c语言-简单小程序-简单算法.doc_第2页
c语言-简单小程序-简单算法.doc_第3页
c语言-简单小程序-简单算法.doc_第4页
c语言-简单小程序-简单算法.doc_第5页
资源描述:

《c语言-简单小程序-简单算法.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、以下小程序都在TC2.0中运行通过,程序没来得及加注释。程序比较简单,都是一些初学c语言时写的程序,请通过运行看效果。5个字符串排序.c#include"stdio.h"#include"stdilb.h"voidpaixu(char*p[5]){inti,j;char*q;for(i=0;i<4;i++)for(j=0;j<4-i;j++)if(strcmp(p[j],p[j+1])>0){q=p[j];p[j]=p[j+1];p[j+1]=q;}}main(){char*p[5];inti;for(i=0;i<5;i++){p[i]=(char*)mallo

2、c(10);scanf("%s",p[i]);}paixu(p);for(i=0;i<5;i++)printf("%s",p[i]);}**********************************************************************************//21根常胜.c#include"stdio.h"#include"conio.h"stick(intleft){inttake;if(left==1){loop1:printf("Howmanystickdoyouwishtotake(1~1)?");flu

3、shall();if(scanf("%d",&take)!=1

4、

5、take>1

6、

7、take<=0){printf("Iserror!");gotoloop1;}printf("Youhavetakenthelaststick.***Youlose!");}else{loop:printf("Howmanystickdoyouwishtotake(1~4)?");flushall();if(scanf("%d",&take)!=1

8、

9、take>4

10、

11、take<=0){printf("Iserror!");gotoloop;}printf("%dst

12、ickleftinthepile.",left-take);printf("Computetake%dstick.",5-take);printf("%dstickleftinthepile.",left-5);stick(left-5);}}main(){system("cls");textbackground(GREEN);textcolor(YELLOW);clrscr();printf("*turn.Eachoneeachtimetakes1to4sticks.The*");printf("*onewhotakesthelaststick

13、willlosethegame.*");printf("***************************************************");printf(">>-------------------GameBegin--------------------");stick(21);printf(">>-------------------GameOver!--------------------");}&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

14、&&&&&&&&&&&&&&&&&&&&&&&&//猜数字游戏#include"stdio.h"#include"stdlib.h"intyuan[4],shu[4];yuan_fen(intnum){yuan[0]=num/1000;yuan[1]=num/100%10;yuan[2]=num/10%10;yuan[3]=num%10;}shu_fen(intnum){shu[0]=num/1000;shu[1]=num/100%10;shu[2]=num/10%10;shu[3]=num%10;}intshudui_panduan(){intshu1[4],

15、shudui=0,i,j,t=0,q,biao=0;for(i=0;i<4;i++)shu1[i]=-1;for(i=0;i<4;i++){for(j=0;j<4;j++){if(shu[i]==yuan[j]){biao=0;for(q=0;q

16、==yuan[i])we

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。