大學(xué)C題庫及答案_第1頁
大學(xué)C題庫及答案_第2頁
大學(xué)C題庫及答案_第3頁
大學(xué)C題庫及答案_第4頁
大學(xué)C題庫及答案_第5頁
已閱讀5頁,還剩42頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、根據(jù)Q5.(io分)寫一個程序根據(jù)從鍵盤輸入的里氏強度顯示地震的后果。-47 - / 111里氏強度地震的后果如下: 里氏強度小于44.05.06.07.0到5.0到6.0到7.0到8.0超過8.0后果很小窗戶晃動墻倒塌;不結(jié)實的建筑物被破壞煙囪倒塌;普通建筑物被破壞地下管線破裂;結(jié)實的建筑物也被破壞 地面波浪狀起伏;大多數(shù)建筑物損毀*輸入格式要求:實數(shù),提示信息:cout << ”請輸入地震的里氏強度: 輸出格式要求:<< endl;"本次地震后果:"本次地震后果:"本次地震后果:"本次地震后果: "本次地震后果: &

2、quot;本次地震后果:很??!"窗戶晃動!"墻倒塌;不結(jié)實的建筑物被破壞!"煙囪倒塌;普通建筑物被破壞!"地下管線破裂;結(jié)實的建筑物也被破壞! 地面波浪狀起伏;大多數(shù)建筑物損毀!#include <iostream> using namespace std; int main()double magnitude;cout <<”請輸入地震的里氏強度:"<< endl;cin >> magnitude;if (magnitude < 4.0)cout <<"本次地震后果:

3、很?。?" << endl;else if(magnitude < 5.0)cout <<"本次地震后果:窗戶晃動!" << endl;else if(magnitude < 6.0)cout <<"本次地震后果:墻倒塌;不結(jié)實的建筑物被破壞!<< endl;else if (magnitude < 7.0)cout <<"本次地震后果: else if (magnitude < 8.0)cout <<"本次地震后果: else

4、cout <<"本次地震后果:煙囪倒塌;普通建筑物被破壞!" << endl;地下管線破裂;結(jié)實的建筑物也被破壞!" << endl;地面波浪狀起伏;大多數(shù)建筑物損毀!" << endl;return 0; Q6.(io分)寫一個程序從鍵盤輸入1到7中的某個數(shù)字,其中1代表星期天,2代表星期一,3代表星期二等。根據(jù)用戶輸入的數(shù)字顯示相應(yīng)的星期幾。如果 用戶輸入的數(shù)字超出了 1到7的范圍,顯示輸出一個錯誤提示信息。*輸入格式要求:整數(shù),提示信息:cout << "Please input

5、 a singlenumeral(1-7):"*輸出格式要求:"Monday”(星期幾的英文單詞首字母大寫加換行)提示信息:"Invalid - please input a single numeral(1-7)."(加換行)#include<iostream> using namespace std; int main() int a;cout << "Please input a single numeral(1-7):"cin >> a;if (a < 1 | a > 7) co

6、ut <<"Invalid - please input a single numeral(1-7).”<< endl switch (a) case 1: cout <<"Sunday" << endl;break ;case 2:cout <<"Monday" << endl;break ;case 3:cout <<"Tuesday" << endl;break ;case 4:cout <<"Wedn

7、esday" << endl;break ;case 5:cout <<"Thursday" << endl;break ;case 6:cout <<"Friday" << endl;break ;case 7:cout <<"Saturday" << endl;break ; return 0;Q7.(io分)有一天,一位百萬富翁遇到一個陌生人,陌生人找他談一個換錢 的計劃,陌生人對百萬富翁說:“我每天給你io萬元,而你第一天只需給我i

8、分錢,第二天我仍給你10萬元,你給我2分錢,第三天我仍給你10萬元,你給 我4分錢。你每天給我的錢是前一天的兩倍,直到滿一個月(30天)為止”, 百萬富翁很高興,欣然接受了這個契約。請編程計算在這一個月中陌生人總計給 百萬富翁多少錢,百萬富翁總計給陌生人多少錢。*輸入提示信息和數(shù)據(jù)格式:無*輸出提示信息和數(shù)據(jù)格式:cout << "百萬富翁給陌生人:"<< toStranger << "元"<< endl;cout<< "陌生人給百萬富翁:"<< toRichma

9、n << "元"<< endl;#include <iostream>using namespace std;int main() int j;double toStranger = 0;/*富翁給陌生人的錢,以元'為單位*/double toRichman = 0;double term = 0.01;/*陌生人給富翁的錢,以元'為單位*/*富翁第一天給陌生人0.01元*/for (j = 1; j <= 30; j+)(toRichman += 100000;/* 陌生人每天給富翁10萬元*/toStranger

10、 += term;term = term * 2;/*富翁每天給陌生人的錢是前一天的兩倍*/)cout <<"百萬富翁給陌生人:"<< toStranger <<"元"<< endl;cout <<"陌生人給百萬富翁:"<< toRichman <<"元"<< endl;return 0;)Q8.(10分)編程計算自然數(shù)的立方和,直到立方和大于等于1000000時為止 統(tǒng)計并輸出實際累加的項數(shù)。輸出格式要求:cout&l

11、t;<"sum="<<sum<<endl;cout << "count =" << i << endl;輸出結(jié)果為:sum=1071225count =45#include <iostream> using namespace std;int main()(long i, sum = 0;for (i = 1; ; i+)(sum = sum + i * i * i;if (sum >= 1000000) break ;)cout<< "sum=&q

12、uot; <<sum<<endl;cout << "count ="<< i << endl;return 0;)Q9.(10分)求多項式1!+2!+3!+15!的值。輸出格式要求:cout<<"s="<<s<<endl;#include<iostream>using namespace std;int main()int n = 1, s = 0;for ( int i = 1; i <= 15; i+)n = n * i;s += n;c

13、out <<"s=" << s << endl;return 0;Q10.(10分)求1至200之間的所有質(zhì)數(shù),將質(zhì)數(shù)和存入變量sum中并輸出。質(zhì)數(shù)(素數(shù))的說明:“質(zhì)數(shù)是只能被1和其本身整除的數(shù)”。輸入提示要求:無輸出結(jié)果格式要求:質(zhì)數(shù)之間以一個空格隔開輸出所有質(zhì)數(shù)后換行輸出:sum=4227#include<iostream>#include<cmath>using namespace std;int main()int N, m, sum = 0;for (m = 2; m <= 200; m+)int

14、 i, tmp = ( int ) sqrt (m);for (i = 2; i <= tmp; i+)if (m % i = 0)break ;if (i > tmp)cout << m <<""sum += m;cout << endl;cout << "sum=" << sum << endl;return 0;Q11.(10分)在一個已知的一維數(shù)組中分類統(tǒng)計正數(shù)和負(fù)數(shù)的個數(shù)。正數(shù)的個數(shù)存入變量C1中量C2中.輸出格式要求:cout << "c

15、1=" << c1 << endl;cout << "c2=" << c2 << endl;#include <iostream>using namespace std;int main()int a10 = 1,-2, 0, 4, -5, 0, 7, 8, -9, 10;int c1 = 0, c2 = 0;int i;for (i = 0; i < 10; i+)if (ai > 0)c1+;else if (ai < 0)c2+;cout <<"c

16、1=" << c1 << endl;cout <<"c2=" << c2 << endl;return 0;Q12.(10分)在包含10個數(shù)的一維整數(shù)數(shù)組a中查找最大元素max和最小元 素 min。輸出格式要求:cout << "最大元素:"<< max << endl;cout << "最小元素:"<< min << endl;#include <iostream>using na

17、mespace std;int main()int a10 = 32, 43, 65, 23, 432, 543, 543, 54, 542, 87;int i;int max, min;max = a0, min = a0;for (i = 1; i < 10; i+)if (ai > max) max = ai;if (ai < min) min = ai;cout <<"最大元素:"<< max << endl;cout <<"最小元素:"<< min <<

18、endl;return 0;Q13.(10分)用while循環(huán)編程,求自然數(shù)1至100之間各奇數(shù)平方和sumi 輸出結(jié)果格式為:sum=166650#include<iostream>using namespace std; int main()int i = 1, sum = 0;while (i <= 100) sum += i * i;i += 2;cout << "sum=" << sum << endl;return 0;Q14.(10分)判斷一個數(shù)23437是否是素數(shù)(要求程序中設(shè)置一個參數(shù)flag,flag

19、 為1代表是素數(shù),為0代表不是) 輸出結(jié)果:0#include<iostream>#include<cmath>using namespace std; int main()int m, n, flag = 1;m = 23437;for (n = 2; n <= m / 2 && flag; n+)if (m % n = 0)flag = 0;cout << flag << endl;return 0;Q15.(10分)已知一個數(shù)m(=252),用循環(huán)求各位數(shù)字之和輸出結(jié)果格式:s=9#include<iostrea

20、m>using namespace std;int main()int m = 252, a, b, c, s;a = m / 100;b = m / 10 % 10;c = m % 10;s = a + b + c;cout <<"s=" << s << endl;return 0;Q16.(10分)已知一個數(shù)m(=252),用循環(huán)求各位數(shù)字之積。輸出結(jié)果格式:f=20#include<iostream>using namespace std;int main() int m, f=1,n;m=252;while (m

21、 !=0) n=m%10;f*=n;m=m/10;cout<< "f=" <<f<<endl;return 0; Q17.(10分)已知10個四位數(shù)輸出所有對稱數(shù)及個數(shù) n。例如1221, 2332 都是對稱數(shù)。設(shè):int m10 = 1221,2243, 2332, 1435, 1236, 5623, 4321,4356, 6754,3234;輸出結(jié)果:12212332#include <iostream>using namespace std; int main()int i, n = 0, m10 = 1221,2243

22、, 2332,1435, 1236, 5623, 4321, 4356,for (i = 0; i < 10; i+) int a, b, c, d;a = mi / 1000;b = mi % 1000 / 100;c = mi % 100 / 10;d = mi % 10;if (a = d && c = b)cout << mi << endl; n+;return 0;Q18.(10分)將1-100之間奇數(shù)順序累加存入n中,直到其和等于或大于200 為止。輸出結(jié)果格式:n=225#include<iostream>using n

23、amespace std;int main()int n = 0, i = 1;while (n < 200)n = n + i;i+;i+;cout <<"n=" << n << endl;return 0;Q19.(io分)從鍵盤上輸入三個整數(shù),編寫程序求出三個數(shù)中的最大值。輸入格式要求:cout<<”請輸入三個整數(shù):"輸出格式要求:cout<<"最大值是:"<<max<<endl;#include <iostream>using name

24、space std;int main()int a, b, c, t, max;cout <<"請輸入三個整數(shù):"cin >> a >> b >> c;if (a < b)t = a;a = b;b = t;if (a < c)t = a;a = c;c = t;max = a;cout <<"最大值是:"<< max << endl;return 0;Q20.(io 分)輸入年份和月份,編寫程序,判斷這一年該月份的天數(shù)。輸入格式要求:cout <<

25、; "請輸入年份和月份:"輸出格式要求:cout << year << " 年"<< month << "月" << "是"<< day << 天。"<< endl;#include<iostream>using namespace std;int main()int year, month, day;cout <<"請輸入年份和月份:"cin >> ye

26、ar >> month;switch (month)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 (year % 400 = 0 | year % 4 = 0 && year % 100 != 0)day = 29;elseday = 28;break ;cout << year <<"年"<< month <

27、<"月" << "是"<< day <<"夭。"<< enreturn 0;Q21.(10 分)編寫程序,求解下面的分段函數(shù):L -10<K<Cy- < K j眈 U輸入格式要求:cout <<"請輸入x:"輸出格式要求:cout <<"y=" << y << endl;#include<iostream> using namespace std; int main

28、()( double x,y;coutvv "請輸入 x:"cin>>x;if (x>-10&&x<0) y=x-8;if (x=0) y=x;if (x>0&&x<10) y=x*x;cout<< "y=" vvywendl; return 0;的最大公約數(shù)。Q22.(io 分)用“輾轉(zhuǎn)相除方法”計算兩個數(shù)x,y 輸入格式要求:無,直接輸入 輸出格式要求:無,直接輸出結(jié)果#include<iostream>using namespace std;int main

29、() int x, y, n;cin >> x >> y;n = x % y;while (n != 0)x = y;y = n;n = x % y;cout << y << endl;return 0;Q23.(i。 分)利用選擇法將下面io個數(shù)按降序排列有如下定義:int n10 = 5, 6, 4, 2, 3, 7, 8, 5, 6, 7輸入格式要求:無輸出格式要求:以逗號分隔降序數(shù)列#include<iostream>using namespace std;int main()int n10 = 5, 6, 4, 2, 3,

30、7, 8, 5, 6, 7, i, j, k, t;for (i = 0; i < 9; i+)k = i;for (j = i + 1; j < 10; j+) if (nk < nj) k = j;t = ni;ni = nk;nk = t;for (j = 0; j < 10; j+) cout << nj <<","return 0;Q24 .(10分)定義數(shù)組,/&入不多于20名若干學(xué)生成績,統(tǒng)計高于平均分的 人數(shù)k,用-1做結(jié)束標(biāo)志。輸入格式要求:無輸出格式要求:cout << "高于

31、平均分的人數(shù):"<< k << endl;#include <iostream>using namespace std;int main()double cj20, aver, sum = 0;int n = 0, k = 0, i;cin >> cj0;while (cjn >= 0)sum += cjn;n+;cin >> cjn;aver = sum /( n-1);for (i = 0; i < n-1; i+) if (cji > aver) k+;cout <<"高于平均分

32、的人數(shù):"<< k << endl;return 0;Q25.(10 分)已知三個數(shù)a,b,c,按由小到大的順序存入a,b,c中并輸出.輸入格式要求:cout << "輸入三個整數(shù):"輸出格式要求:cout << "由小到大的順序是:"<< a << "," << b << ","<<c<<endl;#include <iostream>using namespace std

33、;int main()int a, b, c, t;cout <<"輸入三個整數(shù):"cin >> a >> b >> c;if (a > b)t = a;a = b;b = t; if (a > c)t = a;a = c;c = t; if (b > c)t = b;b = c;c = t;cout <<”由小到大的順序是:"<< a <<"," << b <<"," <<c<&l

34、t;endl;return 0; Q26.(10 分)編程計算 sum=1!+2!+.+9!。輸入格式要求:無輸出格式要求:cout <<"sum= " << sum << endl;#include<iostream> using namespace std; int main() int sum=0;for ( int i=1; i<=9; i+) int x=1;for ( int j=1;j<=i;j+) x=x*j;sum=sum+x; cout << "sum= " &l

35、t;< sum << endl;return 0;Q27.(io 分)編寫函數(shù),刪除字符串中的指定字符,函數(shù)原型為:void deletechar(char *string, char ch);設(shè) char c100 = "abcdabcd aabbccdd"輸出結(jié)果:bcdbcd bbccdd #include<cstring> #include<iostream> using namespace std; void deletechar( char *string, char ch)int i(0), k(0);while (s

36、tringi+ !='0')if (stringi != ch)stringk+ = stringi;stringk ='0' int main () char c100 ="abcdabcd aabbccdd" ;deletechar(c,'a');cout << c << endl;return 0; Q28.(10 分)編寫函數(shù),將一個十進(jìn)制無符號整數(shù)轉(zhuǎn)換為二進(jìn)制整數(shù),函數(shù) 原型為: void transform(char*p,long i,int base=2);#include <ios

37、tream> using namespace std; void transform( char *p, long i, int base = 2) int r(0), k(0);char t128; while (i > 0) r = i % base;if (r < 10)tk = r + 48; else tk = r + 55;i = i / base; k+; k-; r = 0;while (k >= 0) *(p + r) = tk;r+;k-;*(p + r) ='0'int main()char c256;transform©

38、 45678, 2);cout << c << endl;return 0;Q29.(10 分)輸入io個學(xué)生的成績,存放在一個一維數(shù)組中,求出總分和平 均分。輸入提示信息格式要求:cout << "請輸入學(xué)生的分?jǐn)?shù):"輸出結(jié)果格式要求:cout << "學(xué)生的總分是:"<< sum << endl;cout << "學(xué)生的平均分是:"<< aver << endl;#include<iostream>#includ

39、e<iomanip>using namespace std;int main()int a10, sum, aver, i;sum = 0;cout <<”請輸入學(xué)生的分?jǐn)?shù):"for (i = 0; i <= 9; i+)cin >> ai;for (i = 0; i <= 9; i+)sum = sum + ai;aver = sum / 10;cout <<"學(xué)生的總分是:"<< sum << endl;cout <<"學(xué)生的平均分是:"<

40、< aver << endl;return 0;Q30.(i0 分)輸入io個學(xué)生的成績,存放在一個一維數(shù)組中,找出其中的最高分和所對應(yīng)的學(xué)生輸入提示信息格式要求:cout << "請輸入學(xué)生的分?jǐn)?shù):"輸出提示信息格式要求:cout << "第”<< n + 1 << "名學(xué)生的分?jǐn)?shù)最高,是:"<< max << endl;#include<iostream>using namespace std;int main()int a10, max,

41、 i, n;cout <<”請輸入學(xué)生的分?jǐn)?shù):"for (i = 0; i <= 9; i+)cin >> ai;max = a0;for (i = 1; i <= 9; i+) if (max < ai)max = ai;n = i;cout <<"第"<< n + 1 <<"名學(xué)生的分?jǐn)?shù)最高,是:"<< max << endl;return 0;Q31.(10分)求一個3X3矩陣的對角線元素之和。輸入提示信息格式要求:cout <&l

42、t; "請輸入3行3列矩陣的元素:"<< endl;輸出提示信息格式要求:cout << "請輸出這個3行3列的矩陣:"<< endl;cout << "對角線元素之和為:"<< sum << endl;#include<iostream>#include<iomanip>using namespace std;int main()double a33, sum = 0;int i, j;cout <<"請輸入3行3列

43、矩陣的元素:"<< endl;for (i = 0; i < 3; i+)for (j = 0; j < 3; j+) cin >> aij;cout <<"請輸出這個3行3列的矩陣:"<< endl;for (i = 0; i < 3; i+)for (j = 0; j < 3; j+)cout << setw(5) << aij;cout << endl;for (i = 0; i < 3; i+) sum += aii;cout <<

44、"對角線元素之和為:"<< sum << endl;return 0;Q32 .(10分)用公式 兀=4-4/3+4/5-4/7+.) 計算冗的近似值,直到最后一項絕對值小于1e-5輸入格式要求:無輸出結(jié)果格式要求:cout << "pi =" << pi << endl;#include<iostream>using namespace std;int main() double pi = 0;double n = 1;int f = 1;while (4.0 / n >=

45、1e-5) pi = pi + f * 4 / n;n = n + 2;f = -f;cout << "pi ="<< pi << endl;return 0;Q33.(10 分)求一個4X4矩陣的四周元素之和。輸入提示信息格式要求:cout << "請輸入4行4列矩陣的元素:"<< endl;輸出提示信息格式要求:cout << "請輸出這個4行4列的矩陣:"<< endl; cout << "四周元素之和為:"<

46、;< sum << endl;#include <iostream>#include<iomanip> using namespace std;int main() double a44, sum = 0;int i, j;cout <<"請輸入4行4列矩陣的元素:"<< endl;for (i = 0; i < 4; i+)for (j = 0; j < 4; j+)cin >> aij;cout <<"請輸出這個4行4列的矩陣:"<< e

47、ndl;for (i = 0; i < 4; i+)for (j = 0; j < 4; j+)cout << setw(5) << aij;cout << endl;for (i = 0; i < 4; i+)for (j = 0; j < 4; j+)if (i = 0 | i = 3 | j = 0 | j = 3) sum += aii;cout <<"四周元素之和為:"<< sum << endl;return 0;Q34 .(10分)4個學(xué)生學(xué)習(xí)5門功課,要求輸入所有

48、學(xué)生的各門功課的成績, 并分別求出每門功課的平均成績。輸入提示信息格式要求:cout << "輸入第"<< i + 1 << "個學(xué)生成績:"輸出提示信息格式要求:cout << "第"<< i + 1 << " 個學(xué)生平均成績:"<< setprecision(3) << sum / 5 << endl;#include<iostream>#include<iomanip>using

49、 namespace std;int main()double s45, sum;int i, j, n;for (i = 0; i < 4; i+)cout <<"輸入第"<< i + 1 <<"個學(xué)生成績:"for (j = 0; j < 5; j+)cin >> sij;for (i = 0; i < 4; i+)sum = 0;n = 0;for (j = 0; j < 5; j+)sum += sij;cout << "第"<<

50、i +1 << "個學(xué)生平均成績:"<< setprecision(3) << sureturn 0;Q35.a。分)請輸入io個整數(shù)到一個一維數(shù)組,并逆序輸出。輸入提示信息格式要求:無輸出提示信息格式要求:cout << ai << ""#include<iostream>using namespace std;int main() int a10, i;for (i = 0; i <= 9; i+)cin >> ai;for (i = 9; i >= 0;

51、 i-)cout << ai <<""return 0; #include<iostream> using namespace std; int main() int a10, i;for (i = 0; i <= 9; i+)ai = i;for (i = 9; i >= 0; i-)cout << ai <<""return 0;Q36 .(10分)在a數(shù)組和b數(shù)組中放入an+1和bn+1個由小到大的有序數(shù),程序把兩個數(shù)組中的 順序歸并在c數(shù)組中。設(shè):int a10 = 2, 4

52、, 5, 8, 9, 19, an = 5;int b10 = 2, 3, 4, 8, 12, 18, bn = 5;輸出格式要求:輸出結(jié)果用2個空格隔開cout << endl;#include <iostream>using namespace std;int main()int a10 = 2,4, 5, 8, 9, 19, an = 5;int b10 = 2, 3, 4, 8,12,18, bn = 5;int i, j, k, c20, max = 999;aan + 1 = bbn + 1 = max;i = j = k = 0;while (ai !=

53、max) | (bj != max) if (ai < bj)ck = ai;k+;i+;elseck = bj;k+;j+;for (i = 0; i < k; i+)cout << ci <<""cout << endl;return 0;Q37 .(io分)請輸出如下方陣:1222221312221433121443331444331514431555141555551輸出格式要求:數(shù)據(jù)之間用2個空格隔開。#include<iostream>using namespace std;int main()int

54、a77, i, j;for (i = 0; i < 7; i+)for (j = 0; j < 7; j+)if (i = j II i + j = 6)aij = 1;else if (i < j && i + j < 6) aij = 2;else if (i > j && i + j < 6) aij = 3;else if (i < j && i + j > 6) aij = 4;elseaij = 5;for (i = 0; i < 7; i+)(for (j = 0; j <

55、 7; j+)cout << aij <<cout << endl;return 0;Q38.(10分)輸入20個整數(shù),統(tǒng)計非負(fù)數(shù)的個數(shù),并計算它們的和,然后將 非負(fù)數(shù)從小到大進(jìn)行排序并輸出。輸入信息提示要求:無輸出提示信息格式要求:cout<<"非負(fù)數(shù)有:"<<n<<"個"<<endl;cout<<"非負(fù)數(shù)是:"<<endl;cout << setw(5) << ai;cout<<"

56、;非負(fù)數(shù)的和是:"<<s<<endl;cout<<"將非負(fù)數(shù)從小到大排序輸出:"<<endl;cout << setw(5) << ai;#include<iostream>#include<iomanip>using namespace std;int main()(int a20, s = 0, n = 0, i, j, t;for (i = 0; i <= 19; i+)cin >> ai;for (i = 0; i <= 19; i+)(

57、if (ai > 0)( an = ai; n+;) )cout <<"非負(fù)數(shù)有:"<< n <<"個"<< endl;cout <<"非負(fù)數(shù)是:"<< endl;for (i = 0; i < n; i+)cout << setw(5) << ai;cout << endl;for (i = 0; i < n; i+) s = s + ai;cout <<"非負(fù)數(shù)的和是:"&l

58、t;< s << endl;for (i = 0; i <= n - 2; i+)for (j = i + 1; j <= n - 1; j+) if (ai > aj)( t = ai; ai = aj; aj = t;)cout <<"將非負(fù)數(shù)從小到大排序輸出:"<< endl;for (i = 0; i < n; i+)cout << setw(5) << ai;cout << endl; return 0;)Q39 .(10分)輸入io名學(xué)生語文、數(shù)學(xué)、外語課成績,

59、計算每名學(xué)生三門課 的平均成績,輸出每人各科成績及平均成績,并分析三門課程的優(yōu)秀率,90分以上為優(yōu)秀。輸入提示信息格式控制:cout<<"輸入第"<<i+1<<"個學(xué)生成績:"輸出提示信息格式控制:cout<<"第"<<i+1<<"個學(xué)生的各科成績:"cout<<"t平均成績:"<<sum/3<<endl;cout<<"第"<<j+1<&l

60、t;"門課程的優(yōu)秀率為:"<<n/10.0<<endl; #include<iostream> #include<iomanip> using namespace std; int main ()( int score103,sum; int i,j,n;for (i=0;i<10;i+)(cout<< "輸入第"<<i+1<< "個學(xué)生成績:"for (j=0;j<3;j+) cin >>scoreij; for (i=0;i

61、<10;i+)( sum=0;cout<< "第"<<i+1<< "個學(xué)生的各科成績:"for (j=0;j<3;j+) (sum +=scoreij;cout<<setw(4)<<scorei j;cout<< "t平均成績:"<<sum/3<<endl; for (j=0;j<3;j+)(n=0;for (i=0;i<10;i+) if (scorei j >=90) n+;cout<< &qu

62、ot;第"<<j+1<< "門課程的優(yōu)秀率為:"<<n/10.0<<endl; return 0;Q40.(10 分)程序設(shè)計,已知平面上有一個圓,圓心坐標(biāo)為(2,2),半徑r為1。請輸入一個點 M的坐標(biāo)(x,y),判斷點M是在圓內(nèi)、圓上還是在圓外。要點分析:點M到圓心之間的距離 d二,比較d和r的大小確定點與圓的關(guān)系。輸入格式要求:cout <<"請出入點M的坐標(biāo)(x,y):"輸出格式要求:"點M在圓外?!秉cM在圓上?!秉cM在圓內(nèi)"#include <ios

63、tream>#include <cmath>using namespace std;int main ()double x,y,d;cout <<"請出入點M的坐標(biāo)(x,y):"cin>>x>>y;d= sqrt (x-2)*(x-2)+(x-2)*(x-2);if (d>1)cout<<"點 M在圓外。"<<endl;elseif (d=1)cout<<"點 M在圓上。"<<endl;elseif (d<1)cout&l

64、t;<"點 M在圓內(nèi)"<<endl;return 0;Q41.(io分)有若干個數(shù)放入數(shù)組中,計算其中正數(shù)的平均值aver.設(shè):float a6 = 39,-47, 21,2, -8, 15, aver;輸入格式要求:無輸出結(jié)果為:aver=19.25#include<iostream>using namespace std;int main()float a6 = 39,-47, 21,2, -8, 15, aver;int n = 0, j;aver = 0;for (j = 0; j < 6; j+)if (aj > 0)n+

65、;aver += aj;aver/= n;cout << "aver=" << aver << endl;return 0;Q42 .(10分)以下程序的功能是以每行5個數(shù)來輸出300以內(nèi)能被7或17整 除的偶數(shù),并求出其和。輸入格式:無輸出格式:每個數(shù)據(jù)以一個空格隔開,5個一行和另起一行輸出cout << "sum=" << sum<<endl;#include<iostream>using namespace std;int main()int i, n, sum;sum = 0;n = 0;for (i = 1; i < 300; i+)if (i % 7 = 0 | i % 17 = 0)if (i % 2 = 0)sum = sum + i;n+;cout << i <<''if (n % 5 = 0) cout << endl;cout << endl;cout << "sum=" << sum << endl;return 0;Q43.(io 分)判斷輸入的

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論