




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、窗體頂端Q308.(10分)第5章 實驗2:體型判斷。醫(yī)務(wù)工作者經(jīng)廣泛的調(diào)查和統(tǒng)計分析,根據(jù)身高與體重因素給出了以下按“體指數(shù)”進行體型判斷的方法。體指數(shù)計算公式是: t = w /(h*h) 其中:t是體指數(shù);w是體重,其單位為千克;h是身高,其單位為米。根據(jù)給定的體指數(shù)t計算公式,可判斷你的體重屬于何種類型: 當 t18 時,為低體重; 當 18t25 時,為正常體重; 當 25t27 時,為超重體重; 當 t27 時,為肥胖。*輸入提示信息格式:Please enter h,w:n*輸入數(shù)據(jù)格式要求:%f,%f(先讀入身高,再讀入體重,身高以米讀入,體重以千克讀入)*輸出數(shù)據(jù)格式要求:
2、當 t18 時,輸出:Lower weight!n 當 18t25 時,輸出:Standard weight!n 當 25t27 時,輸出:Higher weight!n 當 t27 時, 輸出:Too fat!n窗體底端#include #include main() float t,w,h; printf(Please enter h,w:n); scanf(%f,%f,&h,&w); t = w/(h*h); if(t=18&t=25&t27) printf(Higher weight!n); elseprintf(Too fat!n); return 0; 窗體頂端窗體頂端Q586.(
3、窗體底端10分)編寫一個程序,輸入年份和月份,判斷該年是否是閏年,并根據(jù)給出的月份判斷是什么季節(jié)和該月有多少天?(閏年的條件是年份能被4整除但不能被100整除,或者能被400整除;規(guī)定35月為春季,68月為夏季,911月為秋季,1、2和12月為冬季)。*輸入格式要求:%d,%d 提示信息:Please enter year,month:*輸出格式要求:%d is leap yearn %d is not leap yearn The season is spring/summer/autumn/winter The number of days of this month is %dn程序運行
4、示例如下:實例1:Please enter year,month:2012,112012 is leap yearThe season is autumnThe number of days of this month is 30實例2:Please enter year,month:2013,122013 is not leap yearThe season is winterThe number of days of this month is 31窗體底端#include #include main() int year=0,leap=0,mon=0,day=0; printf(Plea
5、se enter year,month:); scanf(%d,%d,&year,&mon); if(year%100!=0&year%4=0)|(year%100=0&year%400=0) printf(%d is leap yearn,year); leap=1; elseprintf(%d is not leap yearn,year); switch(mon) case 1: case 2: case 12:printf(The season is wintern); break; case 3: case 4: case 5:printf(The season is springn
6、); break; case 6: case 7: case 8:printf(The season is summern); break; case 9: case 10: case 11:printf(The season is autumnn); break; switch(mon) case 1: case 3: case 5: case 7: case 8: case 10: case 12:day=31; break; case 4: case 6: case 9: case 11:day=30; break; case 2: if(leap=1) day=29; elseday=
7、28; printf(The number of days of this month is %dn,day); 窗體頂端Q3161.(10分)請用else if多分支條件判斷語句編程設(shè)計一個簡單的計算器程序。要求:(1)請用戶按以下形式從鍵盤輸入表達式:操作數(shù) 運算符op 操作數(shù)(2)然后計算表達式的值*輸入提示信息*:無*輸入數(shù)據(jù)格式*:%f%c%f*輸出數(shù)據(jù)格式*:%.2f%c%.2f=%.2fn 若若輸入的運算符是除法運算符/,當除數(shù)為0時,輸出數(shù)據(jù)格式為:dat is 0!Error!n 若輸入的運算符不是加(+)、減(-)、乘(*)、除(/),則輸出數(shù)據(jù)格式為:Error!n友情提
8、示: 用戶輸入的運算符為算術(shù)運算符:加(+)、減(-)、乘(*)、除(/)。用字符變量 op 表示; 操作數(shù)和操作數(shù) 為浮點型數(shù)據(jù),分別用浮點型變量 dat1、dat2表示。 程序運行結(jié)果如下所示:1+2 1.00+2.00=3.00#include #include main() float a=0,b=0; char op; scanf(%f%c%f,&a,&op,&b); if(op=+) printf(%.2f%c%.2f=%.2fn,a,op,b,a+b); else if(op=-) printf(%.2f%c%.2f=%.2fn,a,op,b,a-b); else if(op=*
9、) printf(%.2f%c%.2f=%.2fn,a,op,b,a*b); else if(op=/) if(b!=0) printf(%.2f%c%.2f=%.2fn,a,op,b,a/b); elseprintf(dat is 0!Error!n); elseprintf(Error!n); 窗體底端窗體頂端Q3185.(10分)實驗二(2016春劉秉權(quán)C語言課):根據(jù)輸入的百分制成績score,轉(zhuǎn)換成相應(yīng)的五分制成績grade后輸出。轉(zhuǎn)換規(guī)則為(要求用switch語句實現(xiàn)):當score大于等于90且小于等于100時,grade=A;當score大于等于80且小于90時,grade=B
10、;當score大于等于70且小于80時,grade=C;當score大于等于60且小于70時,grade=D;當score大于等于0且小于60時,grade=E。格式要求:輸入提示:Please enter score:輸出形式形如:100-A、75-C、0-E當輸入分數(shù)不正確時,輸出:Input error!#include main() int s,m; printf(Please enter score:); scanf(%d,&s); m=s100?-1:s/10; switch(m) case 10: case 9:printf(%d-An,s); break; case 8:pri
11、ntf(%d-Bn,s); break; case 7:printf(%d-Cn,s); break; case 6:printf(%d-Dn,s); break; case 5: case 4: case 3: case 2: case 1: case 0:printf(%d-En,s); break; default:printf(Input error!); 窗體底端窗體頂端Q221.(10分)編程從鍵盤輸入某年某月(包括閏年),用switch語句編程輸出該年的該月?lián)碛械奶鞌?shù)。要求考慮閏年以及輸入月份不在合法范圍內(nèi)的情況。已知閏年的2月有29天,平年的2月有28天。*輸入格式要求:%d,
12、 %d 提示信息:Input year,month:*輸出格式要求:31 daysn 29 daysn 28 daysn Input error!n程序運行示例如下:Input year,month:2004,229 days#include main() int a, b; printf(Input year,month:); scanf(%4d, %2d, &a, &b); switch (b) case 1: case 3: case 5: case 7: case 8: case 10: case 12: printf(31 daysn); break; case 4: case 6:
13、 case 9: case 11: printf(30 daysn); break; case 2: if (a % 4 = 0 & a % 100 != 0) | a % 400 = 0) printf(29 daysn); elseprintf(28 daysn); break; default: printf(Input error!n); return 0; 窗體底端窗體頂端Q210.(10分)第7章實驗任務(wù)1:所謂素數(shù)是指這個數(shù)只能被1和自身整除。要求在主函數(shù)輸入一個數(shù),調(diào)用函數(shù)Fun()判斷該數(shù)是否是素數(shù)。打印信息在主函數(shù)中進行。例如:從鍵盤輸入5,5是素數(shù)則打印如下信息:5 is
14、 a prime number.又如:從鍵盤輸入4, 4不是素數(shù)則打印如下信息:4 is not a prime number負數(shù)、0和1均不是素數(shù)。對輸入的數(shù)據(jù)要考慮數(shù)據(jù)的合法性,不滿足條件的數(shù)要重新輸入直到滿足條件為止。不能使用全局變量,不按給定的函數(shù)原型編寫程序不給分。Fun()函數(shù)原型如下: int Fun(int m);*輸入數(shù)據(jù)提示信息:Please input a number:n注:該提示信息請放在循環(huán)體外*輸入數(shù)據(jù)格式為:%d*輸出格式要求: 若是素數(shù)輸出數(shù)據(jù)格式為:%d is a prime numbern 若不是素數(shù)輸出數(shù)據(jù)格式為: %d is not a prime n
15、umbern#include #include int Fun(int m); main() int a; printf(Please input a number:n); while (scanf(%d,&a) if (a 0 & a != 1 & Fun(a) = 1) printf(%d is a prime numbern,a); elseprintf(%d is not a prime numbern, a); break; return 0; int Fun(int m) int i, result; result = 1; if (m != 2) for (i = 2; i m;
16、 i+) if (m % i = 0) result = 0; break; return result; 窗體底端窗體頂端Q3185.(10分)實驗二(2016春劉秉權(quán)C語言課):根據(jù)輸入的百分制成績score,轉(zhuǎn)換成相應(yīng)的五分制成績grade后輸出。轉(zhuǎn)換規(guī)則為(要求用switch語句實現(xiàn)):當score大于等于90且小于等于100時,grade=A;當score大于等于80且小于90時,grade=B;當score大于等于70且小于80時,grade=C;當score大于等于60且小于70時,grade=D;當score大于等于0且小于60時,grade=E。格式要求:輸入提示:Pleas
17、e enter score:輸出形式形如:100-A、75-C、0-E當輸入分數(shù)不正確時,輸出:Input error!#include main() int s,m; printf(Please enter score:); scanf(%d,&s); m=s100?-1:s/10; switch(m) case 10: case 9:printf(%d-An,s); break; case 8:printf(%d-Bn,s); break; case 7:printf(%d-Cn,s); break; case 6:printf(%d-Dn,s); break; case 5: case
18、4: case 3: case 2: case 1: case 0:printf(%d-En,s); break; default:printf(Input error!); 窗體底端窗體頂端Q1709.(10分)第6章實驗1:國王的許諾相傳國際象棋是古印度舍罕王的宰相達依爾發(fā)明的。舍罕王十分喜歡象棋,決定讓宰相自己選擇何種賞賜。這位聰明的宰相指著88共64格的象棋盤說:陛下,請您賞給我一些麥子吧,就在棋盤的第1個格子中放1粒,第2格中放2粒,第3格中放4粒,以后每一格都比前一格增加一倍,依此放完棋盤上的64個格子,我就感恩不盡了。舍罕王讓人扛來一袋麥子,他要兌現(xiàn)他的許諾。請問:國王能兌現(xiàn)他的
19、許諾嗎?試編程計算舍罕王共要多少麥子賞賜他的宰相,這些麥子合多少立方米(已知1立方米麥子約1.42e8粒)?注:(1)不能使用指針、結(jié)構(gòu)體、共用體、文件、goto、枚舉類型進行編程。 (2)用標準C語言編程,所有變量必須在第一條可執(zhí)行語句前定義。 (3)輸入輸出格式要和以下給定格式完全一致。*輸入格式:無*輸出格式:sum = %en volum = %en%e表示double類型#include #include main() int i; double s, v; s = 0; for (i = 0; i = 63; i+) s = s + pow(2, i); v = s / 1.42e
20、8; printf(sum = %en, s); printf(volum = %en, v); return 0; 窗體底端窗體頂端Q1719.(10分)第7章實驗任務(wù)3從鍵盤任意輸入一個整數(shù)n,編程計算并輸出1n之間的所有素數(shù)之和輸入提示信息:Input n:輸入格式:%d輸出格式:sum = %dn#include #include int Fun(int m); main() int n,i,s; s=0; printf(Input n:); scanf(%d,&n); for(i=2;i=n;i+) if(Fun(i)=1) s=s+i; printf(sum = %dn,s); r
21、eturn 0; int Fun(int m) int i, result; result = 1; if (m != 2) for (i = 2; i m; i+) if (m % i = 0) result = 0; break; return result; 窗體底端窗體頂端Q1720.(10分)第7章實驗任務(wù)6從鍵盤任意輸入一個整數(shù)m,若m不是素數(shù),則對m進行質(zhì)因數(shù)分解,并將m表示為質(zhì)因數(shù)從小到大順序排列的乘積形式輸出,否則輸出It is a prime number。例如,用戶輸入90時,程序輸出90 = 2 * 3 * 3 * 5;用戶輸入17時,程序輸出It is a prime
22、 number。輸入提示信息:Input m:輸入格式:%d輸出格式:是素數(shù)時輸出It is a prime numbern否則輸出用%d = ,%d * 運行示例1:Input m:9090 = 2 * 3 * 3 * 5運行示例2:Input m:13It is a prime number#include int Fun(int m); int IsPerfect(int m); main() int m,i,p; printf(Input m:); scanf(%d,&m); p=m; if(Fun(m)=1) printf(It is a prime numbern); else p
23、rintf(%d = ,m); for(i=2;im;i+) if(p%IsPerfect(i)=0&p/IsPerfect(i)!=1&IsPerfect(i)!=1) printf(%d * ,i); else if(p%IsPerfect(i)=0&p/IsPerfect(i)=1&IsPerfect(i)!=1) printf(%d,i); break; elsecontinue; p=p/i; while(p%i=0) if(p/i!=1) printf(%d * ,i); p=p/i; else printf(%d,i); break; return 0; int Fun(int
24、m) int i, result; result = 1; if (m != 2) for (i = 2; i m; i+) if (m % i = 0) result = 0; break; return result; int IsPerfect(int m) int i, result; result=1; if (m != 2) for (i = 2; i = m; i+) if (m % i = 0) break; else if(m%i!=1&m/i!=1) continue; elseresult=m; elseresult=2; return result; 窗體底端窗體頂端Q
25、198.(10分)第7章實驗任務(wù)5如果一個正整數(shù)m的所有小于m的不同因子(包括1)加起來正好等于m本身,那么就被稱它為完全數(shù)。它是指這樣的一些特殊的自然數(shù),它所有的真因子(即除了自身以外的約數(shù))的和,恰好等于它本身。注意:1沒有真因子,所以不是完全數(shù)。例如,6就是一個完全數(shù),是因為6 = 1 + 2 + 3。請編寫一個判斷完全數(shù)的函數(shù)IsPerfect(),然后判斷從鍵盤輸入的整數(shù)是否是完全數(shù)。要求:按如下原型編寫判斷完全數(shù)的函數(shù),若函數(shù)返回0,則代表不是完全數(shù),若返回1,則代表是完全數(shù)。int IsPerfect(int x);*要求輸入提示信息為: Input m:n*要求輸入格式為: %
26、d*要求輸出格式為 %d is a perfect numbern%d is not a perfect numbern注:不能使用指針、結(jié)構(gòu)體、共用體、文件、goto、枚舉類型進行編程,主函數(shù)不能使用int main和return 0。#include int IsPerfect(int m); main() int a; printf(Input m:n); scanf(%d, &a); if (IsPerfect(a) = 1) printf(%d is a perfect numbern, a); elseprintf(%d is not a perfect numbern, a);
27、int IsPerfect(int m) int i, s, find; s = 0; for (i = 1; i m; i+) if (m % i = 0) s = s + i; elsecontinue; if (s = m) find = 1; elsefind = 0; return find; 窗體底端窗體頂端Q3168.(10分)編程從鍵盤輸入一個小寫英文字母,將其轉(zhuǎn)換為大寫英文字母,并將轉(zhuǎn)換后的大寫英文字母及其十進制的ASCII碼值顯示到屏幕上。*輸入提示信息*:Please input a low-case letter from keyboard:*輸入數(shù)據(jù)格式*:%c*輸出
28、數(shù)據(jù)格式*:The capital letter and its ASCII value are:%c and %d.提示:從鍵盤輸入一個字符可用scanf也可用getchar#include main() char a; printf(Please input a low-case letter from keyboard:); a = getchar(); a = a - 32; printf(The capital letter and its ASCII value are:%c and %d., a, a); 窗體底端窗體頂端Q3241.(10分)實驗三(2016春劉秉權(quán)C語言課):
29、已知公式e = 1 + 1/1! + 1/2! + 1/3! + . +1/n!, 編程計算e的近似值,直到最后一項的絕對值小于1e-7時為止,輸入e的值并統(tǒng)計累加的項數(shù)。要求:按順序輸出每一個e值,小數(shù)點后保留8位有效數(shù)字,輸出格式形如:e = 2.66666667, count = 4(回車換行,count為累加的項數(shù))#include double fun(int n); main() int i, c; double e; c = 0; e = 0; for (i = 0; i=11; i+) e = e + fun(i); c+; printf(e = %.8lf, count =
30、%dn, e, c); double fun(int n) double result; int i; i = 1; result = 1; do result = result * i; i+; while (i = n); result = 1.0 / result; return result; 窗體底端窗體頂端Q1710.(10分)第7章實驗任務(wù)4:任意輸入一個整數(shù)m,若m不是素數(shù),則輸出其所有不包括1和自身的因子;否則輸出“沒有因子,是素數(shù)”的相關(guān)提示信息。輸入提示信息:Please enter a number:輸入格式:%d輸出格式:有因子時:%dn無因子時:It is a pr
31、ime number.No divisor!n輸入為1,0,-1時:It is not a prime number.No divisor!n#include #include int Fun(int m); main() int a, i; printf(Please enter a number:); scanf(%d, &a); if (Fun(fabs(a) = 1) printf(It is a prime number.No divisor!n); else for (i = 2; i fabs(a); i+) if ( a % i = 0) printf(%dn, i); int
32、 Fun(int m) int i, result; result = 1; if (m != 2 & m != 1) for (i = 2; i m; i+) if (m % i = 0) result = 0; break; else if (m = 1) result = 0; else; return result; 窗體底端窗體頂端Q1718.(10分)第5章實驗1:身高預測。每個做父母的都關(guān)心自己孩子成人后的身高,據(jù)有關(guān)生理衛(wèi)生知識與數(shù)理統(tǒng)計分析表明,影響小孩成人后的身高的因素包括遺傳、飲食習慣與體育鍛煉等。小孩成人后的身高與其父母的身高和自身的性別密切相關(guān)。設(shè)faHeight為其
33、父身高,moHeight為其母身高,身高預測公式為男性成人時身高 = (faHeight + moHeight) 0.54 cm女性成人時身高 = (faHeight 0.923 + moHeight) / 2 cm此外,如果喜愛體育鍛煉,那么可增加身高2%;如果有良好的衛(wèi)生飲食習慣,那么可增加身高1.5%。請編程從鍵盤輸入用戶的性別(用字符型變量sex存儲,輸入字符F表示女性,輸入字符M表示男性)、父母身高(用實型變量存儲,faHeight為其父身高,moHeight為其母身高)、是否喜愛體育鍛煉(用字符型變量sports存儲,輸入字符Y表示喜愛,輸入字符N表示不喜愛)、是否有良好的飲食習慣
34、等條件(用字符型變量diet存儲,輸入字符Y表示良好,輸入字符N表示不好),利用給定公式和身高預測方法對身高進行預測。運行示例:Are you a boy(M) or a girl(F)?FPlease input your fathers height(cm):182Please input your mothers height(cm):162Do you like sports(Y/N)?NDo you have a good habit of diet(Y/N)?YYour future height will be 167(cm)#include main() float fh, m
35、h, h; char sex, sports, diet; printf(Are you a boy(M) or a girl(F)?); sex = getchar(); getchar(); printf(Please input your fathers height(cm):); scanf(%f, &fh); getchar(); printf(Please input your mothers height(cm):); scanf(%f, &mh); getchar(); printf(Do you like sports(Y/N)?); sports = getchar();
36、getchar(); printf(Do you have a good habit of diet(Y/N)?); diet = getchar(); if (sex = M) h = (fh + mh) * 0.54; else if (sex = F) h = (fh * 0.923 + mh) / 2; else printf(Error!n); goto R; if (sports = Y) h = h * 1.02; else if (sports = N); else printf(Error!n); goto R; if (diet = Y) h = h * 1.015; el
37、se if (diet = N); else printf(Error!n); goto R; printf(Your future height will be %.0f(cm)n, h); R: return 0; 窗體底端窗體頂端窗體頂端Q3134.(窗體底端.(10分)第8章實驗1:學生成績管理系統(tǒng)V1.0某班有最多不超過30人(具體人數(shù)由鍵盤輸入)參加某門課程的考試,用一維數(shù)組作函數(shù)參數(shù)編程實現(xiàn)如下學生成績管理:(1)錄入每個學生的學號和考試成績;(2)計算課程的總分和平均分;(3)按成績由高到低排出名次表;(4)按學號由小到大排出成績表;(5)按學號查詢學生排名及其考試成績;(6)
38、按優(yōu)秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(059)5個類別,統(tǒng)計每個類別的人數(shù)以及所占的百分比;(7)輸出每個學生的學號、考試成績。程序運行結(jié)果示例:Input student number(n30):6Management for Students scores1.Input record2.Caculate total and average score of course3.Sort in descending order by score4.Sort in ascending order by number5.Search by number6
39、.Statistic analysis7.List record0.ExitPlease Input your choice:1Input students ID, name and score:11003001 8711003005 9811003003 7511003002 4811003004 6511003006 100Management for Students scores1.Input record2.Caculate total and average score of course3.Sort in descending order by score4.Sort in as
40、cending order by number5.Search by number6.Statistic analysis7.List record0.ExitPlease Input your choice:2sum=473,aver=78.83Management for Students scores1.Input record2.Caculate total and average score of course3.Sort in descending order by score4.Sort in ascending order by number5.Search by number
41、6.Statistic analysis7.List record0.ExitPlease Input your choice:3Sort in descending order by score:1100300610011003005981100300187110030037511003004651100300248Management for Students scores1.Input record2.Caculate total and average score of course3.Sort in descending order by score4.Sort in ascending order by number5.Search by number6.Statistic analysis7.List record0.ExitPlease Input your choice:4Sort in ascending order by number:1100300187110030024811003003751
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 各銀行合同范本
- 口頭勞動合同范例
- 旅游景區(qū)環(huán)境綜合整治專題研究:景區(qū)環(huán)境現(xiàn)狀分析
- 收購老宅物品合同范本
- 熱電行業(yè)分析研究報告
- 科技引領(lǐng)下的綠色企業(yè)發(fā)展戰(zhàn)略
- 中央熱水安裝合同范本
- 單餐用餐合同范本
- 合作方案合同范本
- 醫(yī)療檢驗協(xié)議合同范例
- 外科學教學課件:腰椎間盤突出癥
- 兒童吸入性肺炎的診斷與治療
- 產(chǎn)房分娩安全核查表及使用說明
- oppor11t刷全網(wǎng)通改全教程
- 內(nèi)部控制-倉儲與存貨循環(huán)調(diào)查問卷
- 高二英語期末考試試卷質(zhì)量分析報告
- 第一講酒吧的類型及特征
- JJF 1071-2010國家計量校準規(guī)范編寫規(guī)則
- GB/T 28906-2012冷鐓鋼熱軋盤條
- GB/T 24803.4-2013電梯安全要求第4部分:評價要求
- GB/T 1348-1988球墨鑄鐵件
評論
0/150
提交評論