《西工大C语言POJ习题答案 .》由会员分享,可在线阅读,更多相关《西工大C语言POJ习题答案 .(171页珍藏版)》请在金锄头文库上搜索。
1、一.1.第一季10题全(注:第五题问题已经解决,确认AC!)#includeintmain()inta,b,sum;scanf(%d%d,&a,&b);sum=a+b;printf(%dn,sum);return0;2.#include#definePI3.1415926intmain()doubler,h,l,s,sq,vq,vz;scanf(%lf%lf,&r,&h);l=2*PI*r;s=PI*r*r;sq=4*PI*r*r;vq=4*PI*r*r*r/3;vz=s*h;printf(%.2lfn%.2lfn%.2lfn%.2lfn%.2lfn,l,s,sq,vq,vz);return0
2、; 3.#includeintmain()inta,b,c;doubled,e;scanf(%d%d%d,&a,&b,&c);d=a+b+c;e=d/3;printf(%lfn%lfn,d,e);return0;4.#includeintmain()inta,b,c;scanf(%d%d%d,&a,&b,&c);if(ab)a=b;if(ac)a=c;printf(%dn,a);return0; 5.#includeintmain()inti=0,j=0,k=1;chara6;while(ai=getchar()!=n)i+;for(;i0;i-)if(aj=ai-1)j+;continue;
3、elsek=0;break;if(k=1)printf(yesn);elseprintf(non);6.#includeintmain()doublea,c;scanf(%lf,&a);switch(int)a/10)case0:c=a*0.1;break;case1:c=(a-10)*0.075+10*0.1;break;case2:case3:c=(a-20)*0.05+10*0.075+10*0.1;break;case4:case5:c=(a-40)*0.03+20*0.05+10*0.075+10*0.1;break;case6:case7:case8:case9:c=(a-60)*
4、0.015+20*0.03+20*0.05+10*0.075+10*0.1;break;default:c=(a-100)*0.01+40*0.015+20*0.03+20*0.05+10*0.075+10*0.1;printf(%lfn,c);return0;7.#includeintmain()doublea,b,c;scanf(%lf,&a);c=(int)a;if(ac)a=c+1;if(a15)b=(a-15)*2.1+7+13*1.5;elseif(a2)b=(a-2)*1.5+7;elseb=7;printf(%lfn,b);return0;8.#includeintmain()
5、inta,b,c,e,f=30,g=31,n;scanf(%d-%d-%d,&a,&b,&c);if(a%400=0)|(a%100!=0&a%4=0)e=29;elsee=28;switch(b)case1:n=c;break;case2:n=g+c;break;case3:n=g+e+c;break;case4:n=g+e+g+c;break;case5:n=g+e+g+f+c;break;case6:n=g+e+g+f+g+c;break;case7:n=g+e+g+f+g+f+c;break;case8:n=g+e+g+f+g+f+g+c;break;case9:n=g+e+g+f+g
6、+f+g+g+c;break;case10:n=g+e+g+f+g+f+g+g+f+c;break;case11:n=g+e+g+f+g+f+g+g+f+g+c;break;default:n=g+e+g+f+g+f+g+g+f+g+f+c;printf(%dn,n);return0;9.#includeintmain()intx;scanf(%d,&x);if(x=90&x=80)printf(Bn);elseif(x=70)printf(Cn);elseif(x=60)printf(Dn);elseprintf(En);return0;10.#includeintmain()doublex
7、,y,s;scanf(%lf,%lf,&x,&y);s=(x+2)*(x+2)+(y-2)*(y-2);if(s1)s=(x+2)*(x+2)+(y+2)*(y+2);if(s1)s=(x-2)*(x-2)+(y+2)*(y+2);if(s1)s=(x-2)*(x-2)+(y-2)*(y-2);if(s1)printf(0n);return1;printf(10n);return0;二。第二季15题全11. #includeint main() int x=0,a=0,c=0,i=1;scanf(%d%d,&x,&a);c=x; for(i=1;ia;i+)c=(c*x)%1000;if(c1
8、00)if(c=100)printf(%dn,c);return 0;12. #includeint main() int i=1,a=0,b=0,c=1016,k=1; for(;k=1;)c=c+4;a=c;b=c;for(i=1;i=4;i+) a=a/4*5+1; if(a%4!=0) k=0; ; ;a=a/4*5+1;if(k=1)printf(%d %dn,a,b); break;return 0;13。#include#includeint main()int i=1,n=0,b=0;double j=0,k=0,m=0;scanf(%d,&n); for(;i=n;i+) b
9、=i%2-1; k=pow(-1,b); m=pow(2,i); j+=k*m/(m-k)/(2*m+k);printf(%.6lfn,j);return 0;14. #include#includeint main() int a=0,b=0,i=0,t;scanf(%d%d,&a,&b); if(ab) t=a;a=b;b=t;for(;a=b;a+) int m=1;for(i=2;i=sqrt(a);i+)if(a%i=0)m=0;break; if(m=1)printf(%d ,a);printf(n);return 0;15.#include#includeint main() int a=0,b=0,c=0;scanf(%d,&a); b=(int)pow(a,2);c=(int)pow(a,3);if(a%2) printf(%d*%d*%d=%d=%d,a,a,a,c,b-a/2*2); int n=1; for(;na;n+) printf(+%d,b-a/2*2+2*n); printf(n);if(a%2=0) int n=1; printf(%d*%d*%d=%d=%d,a,a,a,c,b+1-a); for(;na;n+) printf(+%d,b+1-a+n*2); printf(n);return 0;16#include#includeint