《2022年C语言程序设计精髓编程题在线测试 .pdf》由会员分享,可在线阅读,更多相关《2022年C语言程序设计精髓编程题在线测试 .pdf(35页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#include #include int main() intaa, bb, cc; double re; printf(Input math1, English and math2:); scanf(%d,%d,%d, &aa, &bb, &cc); re = ( aa * 5 + bb * 1.5 + cc * 3.5) / 10; printf(Final score = %.2fn, re); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共
2、35 页 - - - - - - - - - #include #include int main() float re; inti, day; printf(Input length and days:); scanf(%f,%d, &re, &day); for ( i=0; i day; i+) re = re / 2; printf(length=%.5fn, re); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 35 页 - - - -
3、- - - - - #include #include int main() float re; printf(Input payment p:); scanf(%f, &re); re = re * 0.92; printf(price = %.1fn, re); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 35 页 - - - - - - - - - #include #include typedefstruct clock int hour,
4、 minute, second; CLOCK; int main() CLOCK clock1,clock2; int diff=0, hour, minute; printf(Input time one(hour, second):); scanf(%d,%d, &clock1.hour,&clock1.minute); printf(Input time two(hour, second):); scanf(%d,%d, &clock2.hour,&clock2.minute); diff = abs(clock1.hour * 60 + clock1.minute) - (clock2
5、.hour * 60 + clock2.minute); hour = floor(diff / 60); minute = diff % 60; printf(%d hour %d secondn,hour, minute); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 35 页 - - - - - - - - - #include #include intgcd(intx,int y) int r=x%y; while(r) x=y; y=r;
6、 r=x%y; return y; int main() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 35 页 - - - - - - - - - inta,b,c,d,t; printf(Input a/b, c/d: ); scanf(%d/%d,%d/%d,&a,&b,&c,&d); if(bd) t=gcd(b,d); else t=gcd(d,b); if(a*d/tc*b/t) printf(%d/%d%d/%d,a,b,c,d); else if(a*d
7、/t=c*b/t) printf(%d/%d=%d/%d,a,b,c,d); else printf(%d/%d%d/%d,a,b,c,d); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 35 页 - - - - - - - - - #include #include int main() int year; doublecapital,rate, deposit; char n; printf(Input rate, year, capital:
8、); scanf(%lf,%d,%lf,&rate, &year,&capital ); printf(Compound interest (Y/N)?); scanf( %c,&n); if(n=n|n=N) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 35 页 - - - - - - - - - deposit=capital*(1+rate*year); else deposit=capital*pow(1+rate),year); printf(deposit
9、 = %.4fn,deposit); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 35 页 - - - - - - - - - #include #include int main() int year; doublecapital,rate,deposit; char n; printf(Input capital, year:); scanf(%lf,%d,&capital,&year); printf(Compound interest (Y
10、/N)?); scanf( %c,&n); if(year=1|year=2|year=3|year=5|year=8) switch(year) case 1:rate=0.0225; break; case 2:rate=0.0243; break; case 3:rate=0.0270; break; case 5:rate=0.0288; break; case 8:rate=0.0300; break; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 35 页
11、- - - - - - - - - if(n=n|n=N) deposit=capital*(1+rate*year); else deposit=capital*pow(1+rate),year); printf(rate = %.4f, deposit = %.4fn,rate,deposit); elseprintf(Error year!n); return 0; #include main() int man , women ,children ; printf( Man Women Childrenn ) ; for(man = 0 ; man 17 ; man+) for(wom
12、en = 0 ; women 25 ;women+) children = 30 -women -man ; if(3*man +2*women + children =50) printf(%3d%8d%8dn ,man,women ,children) ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 35 页 - - - - - - - - - #include void main() int e10,t,d,b,i,j,a; charOK_flag=0; fo
13、r(a=10;a34;a+) d=a*a*a;b=a*a*a*a; e0=d/1000; e1=d/100%10; e2=d/10%10; e3=d%10; e4=b/100000; e5=b/10000%10; e6=b/1000%10; e7=b/100%10; e8=b/10%10; e9=b%10; for(i=0;i9;i+) for(j=i+1;jej) t=ei; ei=ej; ej=t; /if(e=0,1,2,3,4,5,6,7,8,9) for(i=0;i=9;i+) if(ei=i) OK_flag=1; continue; else OK_flag=0; break;
14、if(OK_flag) printf(age=%dn,a); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 35 页 - - - - - - - - - #include int main(void) intyn, jn, i, count = 0; printf(Input your birth year:); scanf(%d, &yn); printf(Input this year:); scanf(%d, &jn); for (i = yn; i= jn;
15、i+) if (i % 4 = 0) printf(%dn, i); count+; printf(count=%dn, count); return 0; #include int main(void) intyn, jn, i; long unsigned count = 0; printf(Input your birth year:); scanf(%d, &yn); printf(Input this year:); scanf(%d, &jn); for (i = yn; ijn; i+) if (i % 4 = 0) count = count + 366 * 24 * 60 *
16、 75; else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 12 页,共 35 页 - - - - - - - - - count = count + 365 * 24 * 60 * 75; printf(The heart beats in your life: %lu, count); return 0; #include long Fact(int n); int main(void) int hundred, ten, one, m, n; for (hundred
17、= 1;hundred = 6;hundred+) for (ten = 0;ten = 6;ten+) for (one = 0;one = 6;one+) m = hundred * 100 + ten * 10 + one; n = Fact(hundred) + Fact(ten) + Fact(one); if (m = n) printf(%dn, n); return 0; long Fact(int n) inti; long s = 1; for (i = 1;i = n;i+) s *= i; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - -
18、 - - - - - - - - 名师精心整理 - - - - - - - 第 13 页,共 35 页 - - - - - - - - - return(s); #include intFunc(int n); int main(void) int n1, m1; printf(Input n:); scanf(%d, &n1); if (n1 1000000) printf(Input error!n); return 0; m1 = Func(n1); printf(%dn, m1); return 0; intFunc(int n) intys, i; for (i = n; i 99;
19、 i-) if (n % i = 0 &i 1000) ys = i; break; returnys; #include intGcd(int a, int b); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 35 页 - - - - - - - - - int main(void) int n1, m1, n2, m2, ys; printf(Input m,n:); scanf(%d,%d, &m1, &n1); if (m1 10000) printf(In
20、put error!n); return 0; ys = Gcd(m1, n1); n2 = n1 / ys; m2 = m1 / ys; printf(%d/%dn, m2, n2); return 0; intGcd(int a, int b) intys, i, temp; if (a 0; i-) if (a % i = 0 & b % i = 0) ys = i; break; returnys; # include intSumPrime(int n) inti; int k; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - -
21、 - - 名师精心整理 - - - - - - - 第 15 页,共 35 页 - - - - - - - - - int sum=0; for(i=2;i=n;+i ) for(k=2;ki;+k) if(i%k=0) break; if(k = i) sum+= k; return sum; int main (void) int n; int sum; printf(Input n:); scanf(%d,&n); sum=SumPrime(n); printf(sum=%dn,sum); return 0; #include #include double Y(double x, in
22、t n); int main(void) int n1; double x1, jieg; printf(Please input x and n:); scanf(%lf,%d, &x1, &n1); jieg = Y(x1, n1); printf(Result=%.2fn, jieg); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 35 页 - - - - - - - - - return 0; double Y(double x, int n) double
23、 sum = 0; inti; for (i = 0; i n; i+) sum = sqrt(sum + x); return sum; #include int Sum(int n); int main(void) int n1, jieg; printf(Please input n:); scanf(%d, &n1); if (n1 0; i-) m1 = m1 + i; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 17 页,共 35 页 - - - - - - - -
24、- return m1; #include int Monkey(int n, int x); int main(void) int n1, gs1 = 1, gs2; printf(Input days n:); scanf(%d, &n1); gs2 = Monkey(n1, gs1); printf(x=%dn, gs2); return 0; int Monkey(int n, int x) inti, sum = 1; for (i = n - 1; i 0; i-) sum = (sum + x) * 2; return sum; #include int main() intc,
25、d; floatw,p; printf(Input payment:); scanf(%f,&p); if(p=1000) c=10; else c=p/100; switch(c) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 18 页,共 35 页 - - - - - - - - - case 0: d=0; break; case 1: d=5; break; case 2: case 3: case 4: d=8; break; case 5: case 6: case 7
26、: case 8: case 9: d=10; break; case 10: d=15; break; default: printf(error); break; w=p*(1-d/100.0); printf(price = %.1fn ,w); return 0; #include int main() inta,n11,i,c,x=0; for(i=1;i=10;i+) scanf(%d,&ni); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 19 页,共 35 页 -
27、 - - - - - - - - scanf(%d,&c); c=c+30; for(i=1;i=10;i+) if(ni=c)x+; printf(%d,x); return 0; #include int main(void) int n1, a11000, i,j, sum, k, count = 0; scanf(%d, &n1); for(i = 0; i n1; i+) scanf(%d, &a1i); for (i = 0; i n1 - 1; i+) for (j = i + 1; j n1; j+) sum = a1i + a1j; for (k = 0; k n1; k+)
28、 if (sum = a1k) count+; printf(%d, count); return 0; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 20 页,共 35 页 - - - - - - - - - #include void separate(int m, int n, int p); int search(int m); int main() inti, j, k, l; int m10; for (i = 123; i333; i+) j = i * 2; k =
29、 i * 3; separate(m, i, 0); separate(m, j, 3); separate(m, k, 6); if (search(m) = 1) printf(%d,%d,%dn, i, j, k); getchar(); return 0; void separate(int m, int n, int p) mp = n / 100; mp + 1 = (n / 10) % 10; mp + 2 = n % 10; int search(int m) inti, j, flag = 1; for (i = 0; i9; i+) for (j = i + 1; j10;
30、 j+) if (mi = mj ) flag = -1; break; if (flag = -1) break; return flag; #include int main(void) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 21 页,共 35 页 - - - - - - - - - int n1, i, j, count = 0, sum = 0, a1 = 0; printf(Input n(n 1; i-) count = 0; for (j = i - 1; j
31、 0; j-) if (i % j = 0) count+; if (count = 2) break; if (count = 1) a1+; if (a1 10) break; printf(%6d, i); sum = sum + i; printf(nsum=%dn, sum); return 0; #include intCountRepeatNum(int count, int n); main() int m, a100; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第
32、 22 页,共 35 页 - - - - - - - - - longint n; printf(Input n:n); scanf(%ld, &n); m = CountRepeatNum(a,n); if(m = 1) printf(Repeated digit!n); else printf(No repeated digit!n); intCountRepeatNum(int count, int n) inti = 0, b,flag = 0; int c, d,k; while(n0) b = n%10; counti = b; n/=10; i+; for(c=0; c=i; c
33、+) for(d=c+1; d 0) return 1; else return -1; #include intIsCancel(int a, int n, int k) inti,s=0; for (i=0;in;i+) if (ai=0) s+; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 23 页,共 35 页 - - - - - - - - - if (sk) return 1; else return 0; int main() int a100; inti,n,k;
34、 printf(Input n,k:n); scanf(%d,%d,&n,&k); for (i=0;in;i+) scanf(%d,&ai); if(IsCancel(a,n,k) printf(YES); else printf(NO); return 0; #include #include main() int a100100,m; intn,i,j,k,max,flag=0,shit=0,l; printf(Input m,n:n); scanf(%d,%d,&n,&l); printf(Input matrix:n); for(i=0; in; i+) for(j=0; jl; j
35、+) scanf(%d,&aij); for(i=0; in; i+) flag=0; m=ai0; for(j=0; jm) m=aij; max=j; for(k=0; kn; k+) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 24 页,共 35 页 - - - - - - - - - if(akmax=m & k!=i) flag=1; break; if(flag=0) printf(a%d%d is %dn,i,max,m);shit=1;break; if (shi
36、t=0) printf(No saddle point!n); #include #include #include intMyatoi(char str) inti,j; for (i=0,j=0;stri!=0;i+) if (stri =0&stri=9) strj=stri; j+; strj=0; returnatoi(str); int main() char s7; printf(Input a string:); scanf(%7s, s); printf(%d, Myatoi(s); printf(n); return 0; 名师资料总结 - - -精品资料欢迎下载 - -
37、- - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 25 页,共 35 页 - - - - - - - - - #include #include #include string.h int find(const char a,const char b) inti,j,flag; for(i=0;i=strlen(a)-strlen(b);i+) if(ai=b0) flag=1; /printf(!n); for(j=1;jstrlen(b);j+) if(ai+j!=bj) flag=0; if(flag=1) break; if(
38、flag!=1) return -1; else return i+1; int main() char a100,b100; int n; printf(Input a string:); gets(a); printf(Input another string:); gets(b); n=find(a,b); if(n!=-1) printf(Searching results:%dn,n); else printf(Not found!n); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - -
39、 - - 第 26 页,共 35 页 - - - - - - - - - return 0; #include #include int main() char a80; int b, i,j,t=1,tl,num=0; printf(Input a string:n); gets(a); for (i=0;istrlen(a);i+) t=1; for (j=i+1;jtl) tl=t; num=i; printf(%c:%dn, anum,tl); #include #include int main() 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - -
40、 - - - - - - - 名师精心整理 - - - - - - - 第 27 页,共 35 页 - - - - - - - - - printf(Input a string:); char save2100; int a, b, i, j; gets(save0); i=0;b=3; for (j = 0; j = A& saveij = a& saveij = A& saveij = a& saveij = z) = 0) saveij -= 26; puts(save0); return (0); #include #include int main(void) printf(Inp
41、ut M,T,U,F,D:); longint m, t, u, f, d; scanf(%ld%ld%ld%ld%ld, &m, &t, &u, &f, &d); printf(Input conditions of road:); char T10000; inti, count = 1; for (i = 0; i 0 &i t) count+; switch (Ti+) caseu:realTime -= (u + d); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 28
42、 页,共 35 页 - - - - - - - - - break; casef:realTime -= (f + f); break; cased:realTime -= (u + d); break; if (realTime 0) count-; printf(num=%ldn, -count); return 0; #include #include int main() int n, i, j, k, o, e; printf(Input n:); scanf(%d, &n); printf(Input numbers:); char sn, oddn, evenn; for (i
43、= 0, j = 0, k = 0; i n; i+) scanf(%d, &si); if (si % 2 = 0) /even evenk+ = si; e = k; else oddj+ = si; o = j; evene = 0; oddo = 0; for (i = 0; i o; i+) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 29 页,共 35 页 - - - - - - - - - if (i = 0) printf(%d, oddi); else prin
44、tf(,%d, oddi); printf(n); for (i = 0; i e; i+) if (i = 0) printf(%d, eveni); else printf(,%d, eveni); return 0; #include #include int main() printf(Input the first string:); char a80,b80; gets(a); if (strlen(a)!=1) printf(Input the second string:); else printf(Input a character:n); gets(b); char *p=
45、strstr(a,b); if (p) printf(Yesn); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 30 页,共 35 页 - - - - - - - - - else printf(Non); return 0; #include #include int main() char s10=Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday; charss10; inti; printf(Please en
46、ter a string:n); gets(ss); for (i=0;i=6;i+) if (strcmp(ss,si)=0) printf(%s is %dn,ss,i);return 0; printf(Not found!n); return 0; #include typedefstructMytime int hour; int min; int sec; T; int main() T t1, t2, t3; int sec1=0, sec2=0, sec3=0; printf(Input time one:(hour, minute):); scanf(%d,%d, &t1.h
47、our, &t1.min); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 31 页,共 35 页 - - - - - - - - - printf(Input time two: (hour,minute):); scanf(%d,%d, &t2.hour, &t2.min); sec1 = t1.hour * 3600 + t1.min * 60 + 0; sec2 = t2.hour * 3600 + t2.min * 60 + 0; if( sec1 = sec2 ) se
48、c3 = sec1 - sec2; else sec3 = sec2 - sec1; t3.hour = sec3 / 3600; sec3 %= 3600; t3.min = sec3 /60; t3.sec = sec3 %60; printf(%dhour,%dminuten, t3.hour, t3.min); return 0; #include typedefstruct winners char name20; intfinalScore; intclassScore; char work; char west; int paper; int scholarship; WIN;
49、int main() printf(Input n:); intn,i; scanf(%d,&n); WIN stun; for (i=0;i80 &stui.paper =1) stui.scholarship+=8000; if (stui.finalScore85 &stui.classScore 80) stui.scholarship+=4000; if (stui.finalScore90) stui.scholarship+=2000; if (stui.finalScore85 &stui.west=Y) stui.scholarship+=1000; if (stui.cla
50、ssScore 80 &stui.work=Y) stui.scholarship+=850; printf(name:%s,scholarship:%dn,stui.name,stui.scholarship); intts=stu0.scholarship,k; for (i=1;in;i+) if (tsstui.scholarship) k=i; printf(%s get the highest scholarship %dn,stuk.name,stuk.scholarship); return 0; #include #include #include #include int