50道C编程练习题及解答
50 道 C/C编程练习题 1、输入 3 个数,求最大值 int main { int a,b,c,m; cinabc; ma; ifbm mb; ifcm mc; coutabc; ifa0 ifb0 cout a; ifa90 coutabc; ifabc else couta; ifamax maxa; ifan; cina; ma; sa; forint i1; ia; s a; ifam ma; } cout n; sum 0; max n; while n -999 { sum sum n; if n max max n; count; cin n; } if count 0 { avestatic_castsum / count; cout1e-18 { pipit; ii1; jj2; tt*i/j; } cout a; ifa0 n; else ifaa; whilea0 { ifa2 0 n a;; else m a; cin a; } cout x; s s x; ifxmax max x; } s s - min - max; cout yearmonthday; fori1; i2 s; cout z; while z 0 { while z xy { coutz; } coutz; } } 49、从 52 个数里选 13 个数 int main { int i,k,a[52],b[13]; fori0; i52; i a[i]i1; srandtime0; fori0; i13; i { k rand 52-i; b[i] a[k]; swapa[k],a[51-i]; } fori0; i13; i coutb[i]“ “; } 50、求 100 const long MOD 10000; int main { int t,t0time0; int len,n100000; unsigned long a[200000]; a[1]1; len1; forint k2; kn; k { long carry0; forint i1; i 0 { len; a[len] carry MOD; carry carry / MOD; } } ttime0; int wlen-1*4 intlog10doublea[len] 1; ofstream fout“factorial.txt“; foutn“ \n“a[len]; fout1;i-- foutsetw4a[i]; foutendl; fout“用时“t-t0“秒“endl; fout“数组元素个数 “len“阶乘值位 数“wendl; return 0; } 8