




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!剪刀石頭布源代碼#include<stdio.h>#include<stdlib.h>main() int d,x; printf("請(qǐng)輸入:1是剪刀,2是石頭,3是布"); scanf("%d",&d); x=rand()%3; if(d=x) printf("雙方平局"); else if(d=1&&x=2)|(d=2&&x=3)|(d=3&&x=1) printf("你贏了")
2、; else printf("電腦贏了"); 傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!簡(jiǎn)單計(jì)算器#include<stdio.h>main()int a,b,d=0;char c;while(d=0) printf("請(qǐng)開始計(jì)算,請(qǐng)輸入需要運(yùn)算的數(shù)字和運(yùn)算法則,數(shù)字 符號(hào) 數(shù)字:"); scanf("%d%c%d",&a,&c,&b); switch(c) case'+': printf("%d+%d=%dn",a,b,a+b); break; ca
3、se'-': printf("%d-%d=%dn",a,b,a-b); break; case'*': printf("%d*%d=%dn",a,b,a*b); break; case'/': if(0=b) printf("除法被除數(shù)不能為零!n") ; else printf("%d/%d=%dn",a,b,a/b); break; 傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!加油站加油問題#include<stdio.h>int main(
4、) double a = 3.25, b = 3.00, c= 2.75; double d = 0.05, e = 0.10, m; int x,y,z; printf("請(qǐng)輸入您要的加油量:"); scanf("%d",&x); printf("請(qǐng)輸入您要的汽油種類,1-a型汽油售價(jià)3.25元/千克, 2-b型汽油售價(jià)3.00元/千克, 3-c型汽油售價(jià)2.75元/千克:"); scanf("%d",&y); printf("請(qǐng)輸入您要的服務(wù)類型,1-自己加 服務(wù)優(yōu)惠0.05,2-協(xié)助
5、加 服務(wù)優(yōu)惠0.10:"); scanf("%d",&z);switch(y) case 1: y = a;break; case 2: y = b;break; case 3: y = c;break; if(z = 1) m = (1 - d) * y * x; else if(z = 2) m = (1 - e) * y * x; printf("您需要支付:%f 元,謝謝惠顧,歡迎下次再來",m); return 0;傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!猜數(shù)字游戲#include<stdio.h>#
6、include<stdlib.h>int main() int d=1,e=0; int a,b,t; printf ("請(qǐng)輸入1-10以內(nèi)的整數(shù),n "); while(d=1) printf("玩家的選擇: "); scanf("%d",&a);do if(a>=0)&&(a<11)break; else printf("錯(cuò)誤"); scanf("%d",&a); while(e=0);b=rand()%10+1;printf(&quo
7、t;npc:%d",b);t=a-b; if(t=0) printf("nright!n"); else if(t<0) printf("n wrong !太小了 n"); else if(t>0) printf("n wrong !太大了 n"); return 0; 傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!萬年歷#include<stdio.h>#include<stdlib.h>void setmonth(int r);void main(void)int year,m
8、onth,day,a,b,i,j,d,x,mon,k;doprintf("-n");printf(" 查全年,輸入 1!n");printf(" 查月份,輸入 2!n");printf(" 查日期,輸入 3!n");printf(" 繼續(xù)?輸入 4!n");printf(" 退出,輸入 5!n");printf("-n");printf("請(qǐng)輸入:");scanf("%d",&x);if(x=1) month
9、=12; printf("輸入年份:");scanf("%d",&year);if(x=2) printf("輸入年份:");scanf("%d",&year);printf("輸入月份:");scanf("%d",&month);if(x=3) printf("輸入年份:");scanf("%d",&year);printf("輸入月份:");scanf("%d"
10、,&mon);printf("輸入日期:");scanf("%d",&day);month=mon-1;傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!if(x=5) exit(100);a=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400)%7; for(i=1,d=0;i<=month;i+)switch(i)case 1:case 3:case 5:case 7:case 8:case 10:case 12:d=31;break;case 2:if(!(year%4)&a
11、mp;&(year%100)|!(year%400) d=29;else d=28;break;case 4:case 6:case 9:case 11:d=30;b=a%7; a+=d; if(x=1) printf("=n");setmonth(i); printf("*n");printf("=n");printf(" 星期一 星期二 星期三 星期四 星期五 星期六 星期天n");for(j=1;j<=b;j+)printf("%8c",' ');for(j=
12、1;j<=d;j+)printf("%8d",j);if(j+b)%7=0)printf("n");傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!if(x=1) printf("n");if(x=2) printf("=n");setmonth(i-1); printf("*n");printf("=n");printf(" 星期一 星期二 星期三 星期四 星期五 星期六 星期天n");for(j=1;j<=b;j+)printf(&q
13、uot;%8c",' ');for(j=1;j<=d;j+) printf("%8d",j);if(j+b)%7=0)printf("n");printf("n");if(x=3) a+=day;a%=7;switch(a)case 0:printf("%d.%d.%d 星期一!",year,mon,day);break;case 1:printf("%d.%d.%d 星期二!",year,mon,day);break;case 2:printf("%d
14、.%d.%d 星期三!",year,mon,day);break;case 3:printf("%d.%d.%d 星期四!",year,mon,day);break;case 4:printf("%d.%d.%d 星期五!",year,mon,day);break;case 5:printf("%d.%d.%d 星期六!",year,mon,day);break;default:printf("%d.%d.%d 星期天!",year,mon,day);printf("n");print
15、f("是否繼續(xù)?輸入4繼續(xù),輸入5退出:"); scanf("%d",&k);while(k=4);if(k=5)傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!exit(100);void setmonth(int r)switch(r)case 1:printf("%4c 一月份",' ');break;case 2:printf("%4c 二月份",' ');break;case 3:printf("%4c 三月份",' ');
16、break;case 4:printf("%4c 四月份",' ');break;case 5:printf("%4c 五月份",' ');break;case 6:printf("%4c 六月份",' ');break;case 7:printf("%4c 七月份",' ');break;case 8:printf("%4c 八月份",' ');break;case 9:printf("%4c 九月份&q
17、uot;,' ');break;case 10:printf("%4c 十月份",' ');break;case 11:printf("%2c 十一月份",' ');break;default:printf("%2c 十二月份",' ');傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!atm機(jī)# include<stdio.h># include<stdlib.h># define password 123456main ()int a,i
18、,b,q,c;float m;m=3000.00;for (i=0;i<=2;i+)printf("請(qǐng)輸入密碼n"); scanf("%d",&a); if(a=password)printf("密碼正確,歡迎使用n");break;elseprintf("密碼錯(cuò)誤,請(qǐng)重新輸入n");if (a!=password)printf("您的操作錯(cuò)誤超過3次,請(qǐng)取回卡n");else system("cls");printf("1.取款n2.存款n3.查詢余
19、額n4.退出n");while(b!=4)scanf("%d",&b); switch(b) case 1: system("cls");printf("請(qǐng)輸入你要取款的金額n"); scanf(" %d",&q); printf("取款成功,請(qǐng)選擇你要進(jìn)行的操作n");m=m-q;break;case 2: system("cls");printf("請(qǐng)輸入你要存入的金額n");scanf(" %d",&am
20、p;c);m=m+c; ;printf("存款成功,請(qǐng)選擇你要進(jìn)行的操作n");break;case 3: system("cls");printf("您的余額為%.2fn",m);break;case 4: system("cls");printf("謝謝使用");break;return 0;傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!學(xué)生成績#include <stdio.h>#include <stdlib.h>float s34;int r=0,c=0
21、;void pjf(void) int i,j,cour = 0; for(j=0;j<4;j+) for(i=0;i<3;i+) cour+=sij; printf("第%d課的平均分是%dn",(j+1),cour/3); cour = 0; void dkzg(void) int i,j,high=0; for(j=0;j<4;j+) for(i=0;i<3;i+) if(sij>high) high=sij; r=i+1; c=j+1; printf("最高分是%d,學(xué)生是%d,課程是%dn",high,r,c);r
22、=0;c = 0;high = 0; int main() int i,j; float score=0; for(i=0;i<3;i+)傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除! printf("enter no.%d scoren",i+1); for(j=0;j<4;j+) scanf("%f",&sij);score += sij; printf("第%d個(gè)學(xué)生的平均分是%fn",(i+1),score/4); score = 0; pjf(); dkzg(); return 0;傳播優(yōu)秀wor
23、d版文檔 ,希望對(duì)您有幫助,可雙擊去除!選票問題#include <stdio.h>void main()int i=1;char j;int num4=0,0,0,0;printf("3位候選人,分別為a,b,c d為無效票,開始投票n");while(i<=10)printf("請(qǐng)輸入第%d個(gè)的選票",i);scanf("%c",&j);switch(j)case 'a':num0+;i+;break;case 'b':num1+;i+;break;case 'c&
24、#39;:num2+;i+;break;case 'd':num3+;i+;break;getchar();printf("a獲得%d張選票n",num0);printf("b獲得%d張選票n",num1);printf("c獲得%d張選票n",num2);printf("無效票為%d張 n",num3);傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!打字母游戲#include <graphics.h>#include <conio.h>#include <ti
25、me.h>#include <stdlib.h>#include <dos.h>#include <stdio.h>/ 歡迎界面void welcome()/ 輸出屏幕提示cleardevice(); /清除屏幕內(nèi)容,用當(dāng)前背景色清空屏幕,并將當(dāng)前點(diǎn)移至 (0, 0)。setcolor(red); /設(shè)置當(dāng)前繪圖前景色為紅色,字體顏色為紅色setfont(64, 0, "黑體");/設(shè)置當(dāng)前字體樣式為黑體,大小為64outtextxy(160, 50, "打字母游戲");/在指定位置輸出字符串。setcolor(
26、green);/設(shè)置當(dāng)前繪圖前景色為綠色,即文字顏色為綠色setfont(16, 0, "宋體");/設(shè)置當(dāng)前字體樣式為宋體outtextxy(200, 200, "本游戲是一個(gè)簡(jiǎn)單傳統(tǒng)的游戲");/在指定位置輸出字符串。outtextxy(200, 240, "就是隨機(jī)出現(xiàn)些字母然后游戲");/在指定位置輸出字符串。outtextxy(200, 280, "者敲鍵盤把它消除用以鍛煉游");/在指定位置輸出字符串。outtextxy(200, 320, "者的反應(yīng)能力,來試試吧");/在指定位置
27、輸出字符串。/ 實(shí)現(xiàn)閃爍的"按任意鍵繼續(xù)"int c=255;while(!kbhit() /沒有按鍵時(shí)循環(huán)繼續(xù)setcolor(rgb(c, 0, 0);/設(shè)置當(dāng)前繪圖前景色為紅色色outtextxy(280, 400, "按任意鍵繼續(xù)");/在指定位置輸出字符串c -= 8; /變量c的值自減去8if (c < 0) c = 255;sleep(20);/調(diào)用sleep()函數(shù)延時(shí)20毫秒getch();/等待用戶從鍵盤按任意一個(gè)鍵,退出循環(huán)cleardevice();/用當(dāng)前背景色清空屏幕,并將當(dāng)前點(diǎn)移至 (0, 0)。/ 難度界面int w
28、elcome2()int i;/ 輸出屏幕提示cleardevice(); /清除屏幕內(nèi)容,用當(dāng)前背景色清空屏幕,并將當(dāng)前點(diǎn)移至 (0, 0)。setcolor(yellow); /設(shè)置當(dāng)前繪圖前景色為黃色,字體顏色為黃色setfont(64, 0, "黑體");/設(shè)置當(dāng)前字體樣式為黑體,大小為64outtextxy(160, 50, "難度選擇");/在指定位置輸出字符串。傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除!setcolor(green);/設(shè)置當(dāng)前繪圖前景色為綠色,即文字顏色為綠色setfont(16, 0, "宋體&qu
29、ot;);/設(shè)置當(dāng)前字體樣式為宋體outtextxy(100, 160, "初級(jí)");/在指定位置輸出字符串。outtextxy(100, 200, "中級(jí)");/在指定位置輸出字符串。outtextxy(100, 240, "高級(jí)");/在指定位置輸出字符串。outtextxy(100, 280, "終極");/在指定位置輸出字符串。 outtextxy(100, 380, "初級(jí)選擇1,中級(jí)選擇2,高級(jí)選擇3,終極4,退出5");scanf("%d",&i);re
30、turn i;/過關(guān)界面void ok()cleardevice();setcolor(yellow);setfont(48, 0, "黑體");outtextxy(104, 180, "恭喜過關(guān),再接再厲");getch();/未過界面void gameover()cleardevice();setcolor(yellow);setfont(48, 0, "黑體");outtextxy(104, 180, " game over");getch();/ 退出界面void goodbye()cleardevice(
31、);/用當(dāng)前背景色清空屏幕,并將當(dāng)前點(diǎn)移至 (0, 0)。setcolor(blue);/設(shè)置當(dāng)前繪圖前景色為藍(lán)色setfont(48, 0, "黑體");/設(shè)置輸出字符串的字體為黑體,大小為48outtextxy(40, 180, "其實(shí)游戲可以適當(dāng)玩玩的!");getch();/等待用戶從鍵盤按任意一個(gè)鍵/ 主函數(shù)void main()int a;initgraph(640, 480);/ 初始化屏幕為 640x480welcome();/ 顯示歡迎界面 bb:a=welcome2();傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除! clea
32、rdevice(); /清除屏幕內(nèi)容,用當(dāng)前背景色清空屏幕,并將當(dāng)前點(diǎn)移至 (0, 0)。srand(time(null);/ 設(shè)置隨機(jī)種子setfont(20, 0, "黑體");/ 設(shè)置字母的字體和大小setfillstyle(black);/ 設(shè)置清除字母的填充區(qū)域顏色char target,target1;/ 目標(biāo)字母char key;/ 用戶的按鍵int x, y,b=51,c=48;/ 字母的位置 switch(a) case 1: while(true) target = 65 + rand() % 26; / 產(chǎn)生任意大寫字母 x = rand() % 55
33、0;/ 產(chǎn)生任意下落位置 for (y=0; y<460; y+) setcolor(green);/ 設(shè)置字母的顏色 outtextxy(x, y, target);setcolor(red); outtextxy(550, 80, "生t命t值"); outtextxy(600, 120, b); setcolor(green); outtextxy(560, 450, "分值"); outtextxy(600, 450, c); if(kbhit() key = getch(); / 獲取用戶按鍵 if(key != target) &
34、;& (key != target + 32) b=b-1; if(key = target) | (key = target + 32) / 按鍵正確,"擊落"字母(畫黑色方塊擦除) bar(x, y, x + 20, y + 20); c=c+1; break;/ 跳出循環(huán),進(jìn)行下一個(gè)字母 else if (key = 27)傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除! goto exit;/ 如果按 esc,退出游戲主循環(huán) if(y=459) b=b-1; if(b=48) goto over; if(c=57) goto win; sleep(10
35、); bar(x, y, x + 20, y + 20); break; case 2: while(true) target = 65 + rand() % 26; / 產(chǎn)生任意大寫字母 x = rand() % 550; / 產(chǎn)生任意下落位置 for (y=0; y<460; y=y+2) setcolor(green);/ 設(shè)置字母的顏色 outtextxy(x, y, target);outtextxy(x+160,y,target1);/ 顯示字母setcolor(red); / 顯示字母 outtextxy(550, 80, "生命值"); outtext
36、xy(600, 120, b); setcolor(green); outtextxy(560, 450, "分值"); outtextxy(600, 450, c); if(kbhit() key = getch();/ 獲取用戶按鍵 if(key != target) && (key != target + 32) b=b-1; if(key = target) | (key = target + 32) bar(x, y, x + 20, y + 20); c=c+1; break; else if (key = 27) goto exit;/ 如果按
37、 esc,退出游戲主循環(huán)傳播優(yōu)秀word版文檔 ,希望對(duì)您有幫助,可雙擊去除! if(y=459) b=b-1; if(b=48) goto over; if(c=57) goto win; sleep(1); bar(x, y, x + 20, y + 20); break; case 3: while(true) target = 65 + rand() % 26; / 產(chǎn)生任意大寫字母 x = rand() % 550;/ 產(chǎn)生任意下落位置 for (y=0; y<460; y=y+1) setcolor(green);/ 設(shè)置字母的顏色 outtextxy(x, y, target);setcolor(red); / 顯示字母 outtextxy(550, 80, "生t命t值"); outtextxy(600, 120, b); setcolor(green); outtextxy(560, 450, "分值"); outtextxy(600, 450, c);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 中學(xué)生青春成長路上的困惑解讀
- 醫(yī)療器械產(chǎn)品使用不當(dāng)風(fēng)險(xiǎn)免責(zé)協(xié)議書
- 農(nóng)業(yè)生產(chǎn)應(yīng)急管理與風(fēng)險(xiǎn)防范方案
- 高考文言文一輪復(fù)習(xí):《元史》專練
- 高考語文答題技巧指導(dǎo)
- 商務(wù)往來溝通文書寫作指南
- 企業(yè)法務(wù)顧問服務(wù)協(xié)議書與風(fēng)險(xiǎn)提示告知書
- 涵洞工程勞務(wù)分包合同
- 高考語文一輪復(fù)習(xí)-文言實(shí)詞盤點(diǎn)8:敝、蔽、便
- 《數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí)指導(dǎo):算法與程序設(shè)計(jì)基礎(chǔ)》
- 《基于舞弊風(fēng)險(xiǎn)因子的輝山乳業(yè)公司財(cái)務(wù)舞弊案例探析》15000字(論文)
- 2025年山西省國有資本運(yùn)營有限公司招聘筆試參考題庫含答案解析
- 2025年湖南生物機(jī)電職業(yè)技術(shù)學(xué)院高職單招職業(yè)適應(yīng)性測(cè)試近5年??及鎱⒖碱}庫含答案解析
- DB1331T 102-2025雄安新區(qū)應(yīng)急物資儲(chǔ)備庫建設(shè)規(guī)范
- 北京市豐臺(tái)區(qū)2024-2025學(xué)年九年級(jí)上學(xué)期期末道德與法治試題(含答案)
- 醫(yī)院培訓(xùn)課件:《PET-CT的臨床應(yīng)用》
- 《從外觀看豬病診治》課件
- 《莫比烏斯環(huán)》課件
- 2025海南省交通投資控股限公司招聘30人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 《工業(yè)機(jī)器人現(xiàn)場(chǎng)編程》課件-任務(wù)3.涂膠機(jī)器人工作站
- 富饒的西沙群島課件
評(píng)論
0/150
提交評(píng)論