




版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、old numbernew numberoldnewoldoldnew3.1. 輸入一個不超過五位的正整數(shù), 輸出其逆數(shù)。例如輸入 12345, 輸出應為 54321 。#include stdio.hmain()long n;int ww,qw,bw,sw,gw; printf(Please input:n); scanf(%ld,&n); while(n99999)printf(nThe number is too little or too large.Retry please!n);scanf(%ld,&n); if(n=10000&n=1000&n=100&n=10&n=99)sw=
2、n/10; gw=n%10; printf(The old number is:%ldn,n);printf(The new number is:%d%dn,gw,sw);else printf(The number equals the number:%ld,n);2.計算1+2+3+n的值,n是從鍵 盤輸入的自然數(shù)。/* Note:Your choice is C IDE */ #include stdio.h main()int n,i;long sum=0;printf(1+2+3+nn);printf(Please input n:n); scanf(%d,&n);for(i=1;i
3、=n;i+)sum+=i;printf(sum=%ld,sum);從終端(鍵盤)讀入 20 個數(shù)據(jù) 到數(shù)組中,統(tǒng)計其中正數(shù)的個 數(shù),并計算這些正數(shù)之和。 、 /* Note:Your choice is C IDE */ #include stdio.h #define N 20 main() int aN,i,sum=0,count=0;printf(Pleaseinputnumbers :n);for(i=0;i0) sum+=ai; count+;input printf(count=%d,sum=%d,co unt,sum);4. 從終端(鍵盤)將 5 個整數(shù)輸入 到數(shù)組 a 中,然后
4、將 a 逆序復制 到數(shù)組 b 中,并輸出 b 中各元素 的值 。/* Note:Your choice is C IDE */ #include stdio.h #define N 5 main() int aN,bN,i;printf(Please numbers:n);for(i=0;iN;i+)scanf(%d,&ai);bN-i-1=ai; printf(nThe are:n);for(i=0;iN;i+) printf(%-4d,ai);printf(nThe new are:n);for(i=0;iN;i+) printf(%-4d,bi);oldnumbersnumbers5.
5、要將五張 100 元的大鈔票, 換成 等值的 50 元, 20 元, 10 元, 5 元一張的小鈔票, 每種面值至少 1 張,編程輸出所有可能的換法, 程序應適當考慮減少重復次數(shù)。/* Note:Your choice is C IDE */#include stdio.hmain() int i,j,k,n;for(i=1;i=10;i+) for(j=1;j=25;j+) for(k=1;k=50;k+)for(n=1;n=100;n+)if(i*50+j*20+k*10+n*5=500)printf(num50=%d,num20=%d,n um10=%d,num5=%dn,i,j,k,n
6、); 6. 求n以內(nèi)(不包括n)同時能被3和 7整除的所有自然數(shù)之和的 平方根 s, n 從鍵盤輸入。例如 若 n 為 1000 時,函數(shù)值應為: s=153.909064 。/* Note:Your choice is C IDE */ #include stdio.h#include math.h main() int n,s,i; float sum=0; printf(Please input n:n);scanf(%d,&n); while(n=0) printf(nError input.Retry please:n);scanf(%d,&n);for(i=1;in;i+)if(i
7、%3=0&i%7=0)sum+=i;printf(Theis:%4.2f,sqrt(sum);7. 一輛卡車違反交通規(guī)則, 撞人后 逃跑?,F(xiàn)場有三人目擊事件,但 都沒有記住車號, 只記下車號的 一些特征。甲說:牌照的前兩位 數(shù)字是相同的;乙說:牌照的后 兩位數(shù)字是相同的, 但與前兩位 不同;丙是數(shù)學家,他說:四位 的車號剛好是一個整數(shù)的平方。 請根據(jù)以上線索找出車號。/* Note:Your choice is C IDE */ #include stdio.h#include math.h main()int i,qw,bw,sw,gw;numberfor(i=1122;i=9988;i+)
8、if(sqrt(i)!=(int)sqrt(i)continue; qw=i/1000; bw=i/100%10; sw=i/10%10; gw=i%10; if(qw=bw&sw=gw)numberprintf(nTheis:%dn,i);break;int i,count=0;for(i=106;i596;i=i+10)if(i%3=0&i%5!=0)8. 輸入 110 之間的一個數(shù)字,輸出它對應的英文單詞。printf(%-4d,i);/* Note:Your choice is C IDE */count+;#include stdio.hmain()printf(count=%-4d
9、,count);int n;printf(Please input n:n);10. 用自然語言描述程序邏輯如下,scanf(%d,&n);試寫程序。while(n10) 設置環(huán)境; 定義變量i、j、s,以及用printf(Error于放置結果的變量 sum并令sum初input!Retry please:n);值為 0;scanf(%d,&n);i=1 ;如果i 100,則轉,否switch(n)則轉;令s=0,求前i個自然數(shù)之case和,并放于變量 s 之中;1:printf(One!);break; sum=sum+s;case i 增加 1 ,轉;2:printf(Two!);brea
10、k;輸出和sum,結束。case/* Note:Your choice is C IDE3:printf(Three!);break;*/case#include stdio.h4:printf(Four!);break;main()case5:printf(Five!);break;int i,j;caselong s=0,sum=0;6:printf(Six!);break;caseprintf(1+1+2+1+2+3+1+2+3+47:printf(Seven!);break;+1+2+3+.+nn);casei=1;8:printf(Eight!);break;while(i=3)ca
11、se9:printf(Nine!);break;s+=i;casesum+=s;10:printf(Ten!);break;i+;iJprintf(sum=%ld,sum);9. 個位數(shù)為 6 且能被 3整除但不能被 5 整除的三位自然數(shù)共有多少11. 用自然語言描述的程序邏輯為:個,分別是哪些? 設置環(huán)境;/* Note:Your choice is C IDE */ 定 義 變 量 i 、 flag 和#include stdio.hpassword ,并令 flag=0 ,i=0 ;main() 用戶回答口令,將其賦于 string length is please!n);flag=1;
12、break; printf(Wrongplease!n); digit ; 中;輸入原始正整數(shù) x ; 從 x 中分解出個位數(shù)字合并個位 digit 至逆數(shù) yinputpassword 變量; 口令正確? 如果是 ,則flag=1,轉。否則轉; 回答三次口令了嗎?如果 沒有,計數(shù)器加1后(i+ ),轉, 否則轉; 根據(jù) flag 之值輸出相應信 息。/* Note:Your choice is C IDE*/#include stdio.h#include string.h #define N 6 main() int i=0,flag=0;char passwordN;printf(The
13、passwordis:123456n);while(i3)gets(password);if(strlen(password)!=6)printf(The wrong!Retryi+; continue;if(strcmp(123456,password)=0)elseinput!Retryi+;if(flag=1)printf(Right password!n);elseprintf(Wrongpassword!n);12. 用自然語言描述的程序邏輯如 下: 設置環(huán)境; 定義變量 digit 、x、y 分別 表示原始數(shù)、原始數(shù)的個位數(shù)和逆 數(shù);原始 數(shù) x 縮小 10 倍 :x=x/10 ;
14、 如果x非零,則轉; 輸出逆數(shù) y ,結束/* Note:Your choice is C IDE*/#include stdio.hmain()long digit,x,y;/* 個 位 數(shù)、原始數(shù)、逆數(shù) */printf(Please input the old number:n);scanf(%ld,&x);digit=x%10;y=digit;while(x!=0)x=x/10; digit=x%10; y=y*10+digit;printf(x=%ld,y=%ld,x, y/10);13. 輸入某三角形的三個邊的長度, 判斷出這是個什么三角形(等 腰、等邊、任意,或不能構成) 。/*
15、 Note:Your choice is C IDE */#include stdio.hmain()float a,b,c,flag;/*flag=0 不 能 , flag=1 等 邊 ,flag=2 等 腰, flag=3 任意 */printf(Pleaseangles:n); scanf(%f,%f,%f,&a,&b,&c); if(a+b=c|a+c=b|b+c=a)flag=0;else if(a=b&b=c)flag=1;elseif(a=b|b=c|c=a)flag=2;if(flag=0) not!n);if(flag=1)Bian.n); if(flag=2)Yao.n);
16、if(flag=3) tong.n); 14. 輸入 10else flag=3;printf(nCanprintf(nDengprintf(nDengprintf(nPu個數(shù),分別統(tǒng)計其中正數(shù)、負數(shù)、零的個數(shù)。#include stdio.h #define N 10 main() int aN;int i,count1=0,count2=0,count3=0;/* count1 記錄正數(shù)個數(shù), count2 記錄 負數(shù)個數(shù), count3 記錄 0 的個數(shù) */ printf(Please input numbers:n);for(i=0;i0) count1+;if(ai0) count
17、2+;if(ai=0) count3+; printf(count1=%-4d,count2=%-4d ,count3=%-4d,count1,count2,cou nt3);15. 先隨機產(chǎn)生 N 個三位自然數(shù)輸 出,然后再輸出其中同時是 3、5、 7 倍數(shù)的數(shù)。(設 N 為 100)/* Note:Your choice is C IDE */#include stdio.h #define N 100 #include #include main() int aN,i; printf(Please numbers:n);inputrandomize(); for(i=0;iN;i+)ai
18、=random(900)+100;printf(%-4d,ai);n);printf(n3,5,7:n);for(i=0;iN;i+)if(ai%3=0&ai%5=0&ai%7=0)printf(%-4d,ai);16. 用 for 編程找出 100200 中的完全平方數(shù)。#include stdio.h#include math.hmain()int i;for(i=100;i=200;i+) if(sqrt(i)=i%100) printf(%-4d,i);17. 從終端輸入三個正實數(shù), 判斷這 三個數(shù)能否構成直角三角形 。#include stdio.h main() float a,b
19、,c,flag;/*flag=0 能, flag=1 能*/printf(Please angles:n);scanf(%f,%f,%f,&a,&b,&c); while(a=0|b=0|c=0) printf(Wrong input!Retry please:n);inputscanf(%d,%d,%d,&a,&b,&c); if(a+b=c|b+c=a|a+cN) printf(Wrong input!Retry please!n);gets(a);input thestrcpy(b,a); strrev(a); if(strcmp(a,b)=0) printf(nYes!n);else
20、printf(nNo!n);20. 隨機產(chǎn)生 N 個大寫字母輸出, 然 后統(tǒng)計其中共有多少個元音字 符。(設N為200) /* Note:Your choice is CIDE */ #include stdio.h #include #include #define N 200 main() int cN,i,count=0; randomize();for(i=0;iN;i+)ci=random(27)+65;printf( %c,ci);if(ci=A|ci=E|ci=I|ci=O|ci=U)count+;printf(nn);printf(ncount=%-4d,count);找出三位
21、自然數(shù)中的所有素數(shù), 要 求判斷 x 素 數(shù)用自 定義 函數(shù) data(x) 實現(xiàn)。#include stdio.hint data(int x);main()int i,flag=0;/*1是, 0否*/for(i=101;i=999;i+)flag=data(i);if(flag=1)printf(%-4d,i);int data(int x)int i;for(i=2;ix/2;i+) if(x%i=0) return 0;satr(m)if(i=x/2)return 1;else return 0;21. 輸出 n 行由“ #”組成的矩形, 每行“#”的個數(shù)為m個,其中n、 m由終端(
22、鍵盤)輸入。要求輸 出m個“ #”功能由函數(shù) 函數(shù)實現(xiàn)。#include stdio.hvoid satr(int m);main() int i,n,m;printf(Pleasen&m:n); printf(n=); scanf(%d,&n); printf(m=); scanf(%d,&m);inputprintf(nn);for(i=1;i=n;i+)satr(m); printf(n);void satr(int m) int i;for(i=1;i=m;i+) printf(#);222. 若 ax +bx+c=0 有實根,#include stdio.h#include math
23、.h main()int a,b,c;float derta,x1,x2; printf(Please input a,b,c:n);printf(a=); scanf(%d,&a);printf(b=); scanf(%d,&b);printf(c=); scanf(%d,&c);則求之。derta=b*b-4*a*c;if(derta0) printf(Two!n);x1=(-b+sqrt(derta)/(2*a);x2=(-b-sqrt(derta)/(2*a); printf(x1=%-4.2f,x2=%-4.2f ,x1,x2);23. 從鍵盤輸入兩個字串, 判斷它們 是否相同。#i
24、nclude stdio.h#include string.h#define N 20main()char c1N,c2N;printf(Please input two string below:n);gets(c1);gets(c2);printf(-n);printf(The answer is:); if(strcmp(c1,c2)=0) printf(Equal!n);elseprintf(Notequal!n);24. 從鍵盤輸入兩個字串, 輸出其中 較短的那個字串, 并輸出它的長 度。#define N 20#include stdio.h#include string.h ma
25、in()char c1N,c2N;printf(Please input two string below:n);gets(c1);lengthlengthlengthinput!Retryntemp=ai; ai=aj;aj=temp;gets(c2);printf(-n); printf(The answer is:); if(strlen(c1)=strlen(c2) puts(c1);puts(c2);printf(Theis:%dn,strlen(c1); if(strlen(c1)strlen(c2) puts(c2);printf(Theis:%dn,strlen(c2);25.
26、 從鍵盤輸入長度不等的兩個字 串,將短串連接于長串之后輸 出。#include stdio.h#include string.h#define N 20main()char c1N,c2N;printf(Please input two string below:n);gets(c1);gets(c2);while(strlen(c1)=strlen(c2)printf(Wrong please:n);gets(c1);gets(c2);printf();printf(The answer is:); if(strlen(c1)strlen(c2) puts(strcat(c1,c2);26.
27、 從鍵盤輸入長度不等的兩個字串,將長串連接于短串之后輸出#include stdio.h#include string.h#define N 20main() char c1N,c2N;printf(Please input two string below:n);gets(c1);gets(c2); while(strlen(c1)=strlen(c2 ) printf(Wrong input!Retry please:n);gets(c1);gets(c2);printf(-n);printf(The answer is:);if(strlen(c1)strlen(c2) puts(str
28、cat(c2,c1);27. 隨機產(chǎn)生 N 個兩位自然數(shù), 降序排列后輸出。(設N為20)#include stdio.h#include stdlib.h#include time.h#define N 20main() int aN,i,j,temp;randomize();for(i=0;iN;i+)ai=random(900)+100;for(i=0;iN-1;i+) for(j=i+1;jai) for(i=0;iN;i+) printf(%-4d,ai);28. 從鍵盤輸入兩個字串, 輸出其中 較長的那個字串, 并輸出它的長 度。twolengthlengthlengthinput
29、averageninputaverageninputn#define N 20 #include stdio.h #include string.h main() char c1N,c2N; printf(Please input string below:n);gets(c1); gets(c2); printf(-n); printf(The answer is:); if(strlen(c1)=strlen(c2) puts(c1);puts(c2); printf(The is:%dn,strlen(c1); if(strlen(c2)strlen(c1) puts(c2); prin
30、tf(The is:%dn,strlen(c2); 29. 從鍵盤輸入 10 個戰(zhàn)士的身高, 輸出平均身高, 并找出哪些身高 低于平均身高。#include stdio.h #define N 11 main() float aN,sum=0;int i; printf(Please heigths:n);for(i=0;iN-1;i+) scanf(%f,&ai); sum+=ai; aN-1=sum/(N-1); printf(The is:%-6.2fn,aN-1);printf();printf(The answer are:n); for(i=0;iN-1;i+) if(aiaN-1
31、)printf(%-8.2f,ai);30. 從鍵盤輸入 10 個戰(zhàn)士的身高, 輸出平均身高, 并找出哪些身高 高于平均身高。#include stdio.h#define N 11main() float aN,sum=0;int i;printf(Please heigths:n);for(i=0;iN-1;i+)scanf(%f,&ai);sum+=ai;aN-1=sum/(N-1); printf(The is:%-6.2fn,aN-1);printf();printf(The answer are:n); for(i=0;iaN-1)printf(%-8.2f,ai);31. 從鍵盤
32、輸入 10 個戰(zhàn)士的身高, 輸出最高、最低的身高#include stdio.h#define N 10 main() float aN,min=99999,max=-99999;int i;printf(Pleaseheigths:n);for(i=0;iN;i+)scanf(%f,&ai);printf();for(i=0;imax)max=ai;if(aimin)min=ai;printf(max=%-6.2f,min=%-6.2f, max,min);。32. “百錢百雞” 問題。百錢買百雞, 雞翁一值錢三,雞母一值錢二, 雞雛三值錢一,問雞翁、雞母、 雞雛各幾何?#include s
33、tdio.hmain() int jw,jm,jc;/* 公雞最多 100/3=33 只,母雞 最多 100/2=50 只, 小雞最多 300只*/ for(jw=1;jw=33;jw+) for(jm=1;jm=50;jm+)for(jc=1;jc=300;jc+)if(jw*3+jm*2+jc/3=100&jw+ jm+jc=100)printf(JW=%d,JM=%d,JC=%dn ,jw,jm,jc);33. 有三個小孩, 一個比一個大 2 歲,已知其年齡之和為 39,問這三個小孩各幾歲?#include stdio.hmain() int a,b,c;for(a=1;a=20;a+)for(b=1;b=20;b+)for(c=1;c=20;c+)if(a+2=b&b+2=c&a+b+c=39)printf(The ages are:%-4d%-4d%-4d,a,b,c); 34. 鍵盤輸入長方體的長寬高h,求其體積及表面積。要求用l 、 w、自定
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 高一數(shù)學二次函數(shù)與幾何圖形結合教學
- 交通車輛租賃協(xié)議書
- 地產(chǎn)行業(yè)智慧物業(yè)管理服務平臺
- 中、大功率激光器相關行業(yè)投資方案
- 行車調(diào)度年終總結
- 預防留置尿管的感染措施
- 市場調(diào)研專員簡歷
- 紅磚采購合同協(xié)議書
- 員工借調(diào)合同協(xié)議
- 物業(yè)公司客戶滿意度調(diào)查表(完整版)
- 《綠色建筑評價標準》解讀
- 物料吊籠安全技術標準
- 《幼兒園課程》試題庫及答案2021
- 干細胞技術與臨床應用0718合一康
- 鍋爐房風險管控措施告知牌
- 苔花如米小“艷過”牡丹開——名著導讀之《簡愛》
- 《西方服裝發(fā)展史》PPT課件(完整版)
- 《食管裂孔疝》PPT課件(完整版)
- 家庭醫(yī)生工作室和家庭醫(yī)生服務點建設指南
- 魯班尺和丁蘭尺速查表
- 企業(yè)年會搞笑相聲劇本《治病》
評論
0/150
提交評論