《NOJ&西工大C程序设计实验习题库(20某)》由会员分享,可在线阅读,更多相关《NOJ&西工大C程序设计实验习题库(20某)(73页珍藏版)》请在金锄头文库上搜索。
1、1计算A+B#include int main() int a,b,sum; scanf(%d%d,&a,&b); sum=a+b; printf(%dn,sum); return 0;2圆及圆球等相关的计算#include #include #define PI int main() double r,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=PI*r*r*r*4/3; vz=PI*r*r*h; printf(%.2lfn%.2lfn%.2lfn%.2lfn%.2lfn%,l,s,sq,v
2、q,vz); return 0;3计算成绩#include int main() double ma,en,c,sum,ave; scanf(%lf%lf%lf,&ma,&en,&c); sum=ma+en+c; ave=sum/3; printf(%lfn%fn,sum,ave); return 0;4找最大数#include int main() int A,B,C,m; scanf(%d%d%d,&A,&B,&C); if(AB) m=A; else m=B; if(mC)m=C; printf(%dn,m); return 0; 5找幸运数#include#includeint mai
3、n()int n;scanf (%d,&n);if(n10)printf(yesn);else if(n100)&(n%10=n/10)printf(yesn);else if(n1000)&(n%10=n/100)printf(yesn);else if(n10000)&(n/1000=n%10)&(n/10%10=n/100%10)printf(yesn);else if(n100000)&(n%10=n/10000)&(n/10%10=n/1000%10)printf(yesn);else printf(non);return 0;6奖金发放#include#include int ma
4、in() double a,b; scanf(%lf,&a); if (a10) if(a20) if(a40) if(a60) if(a100) b=+(a-100)*; else b=+(a-60)*; else b=+(a-40)*; else b=+(a-20)*; else b=1+(a-10)*; else b=a*; printf(%.6lf,b); return 0;7出租车费#include #include int main() double a,b; scanf(%lf,&a); if(a=2)b=7; else if(a15) if(a=(int)a) b=+*(a-1
5、5); else b=+(int)(a-15)+1)*; printf(%.6lfn,b); return 0;8是该年的第几天#include #include int main() int y,m,d,days,sum; scanf(%d-%d-%d,&y,&m,&d); if(y%4=0&y%100!=0)|(y%400)days=29; else days=28; switch(m) case 1:sum=d;break; case 2:sum=31+d;break; case 3:sum=31+days+d;break; case 4:sum=62+days+d;break; cas
6、e 5:sum=92+days+d;break; case 6:sum=123+days+d;break; case 7:sum=153+days+d;break; case 8:sum=184+days+d;break; case 9:sum=215+days+d;break; case 10:sum=245+days+d;break; case 11:sum=276+days+d;break; case 12:sum=306+days+d;break; printf(%d,sum); return 0;9成绩转换#include #include #include #include int
7、 main() int s; scanf(%d,&s); if(s=90)printf(An); else if(s=80)printf(Bn); else if(s=70)printf(Cn); else if(s=60)printf(Dn); else printf(En); return 0;10求建筑高度#include #include int main() double x,y; scanf(%lf,%lf,&x,&y); if (x-2)*(x-2)+(y-2)*(y-2)=1) printf(10); else if (x+2)*(x+2)+(y-2)*(y-2)=1) pri
8、ntf(10); else if (x+2)*(x+2)+(y+2)*(y+2)=1) printf(10); else if (x-2)*(x-2)+(y+2)*(y+2)=1) printf(10); else printf(0); return 0;11多项式的猜想#include #include int main() int x=1,y=1,n=2,sum=2,t; while(sum=100) t=x; x=y; y=t+2*y; sum=sum+y; n+; printf(%dn,n-1);while(sum=1000)t=x;x=y;y=t+2*y;sum=sum+y;n+;p
9、rintf(%dn,n-1);while(sum=10000) t=x; x=y; y=t+2*y; sum=sum+y; n+;printf(%dn,n-1);12整数位数#include#includeint main() double a=0;int i=0,b=0;scanf(%lf,&a); b=(int)a;for(;(int)(b/pow(10,i);)i+; printf(%dn,i);return 0;13五猴分桃#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
10、;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;14你会存钱吗#include#includeint main() int a=0,b=0,c=0,d=0,e=0,x=0,y=0,z=0,u=0,v=0; double f=0;for(a=0;a=2;a+)double m=0;for(b=0;b=(20-8*a)/5;b+)for(c=0;c=(20-8*a-5*b)/3;c+)for(d=0;d=(20-8*a-5*b-3*c)/2;d+)e=20-8*a-5*b-3*c-2*d; m=2000*pow(1+*12*8,a)*pow(1+*12*5,b)*pow(1+*12*3,c)*pow(1+*12*2,d)*pow(1+*12,e);if(fm)f=m; x=a,y=b,z=c,u=d,v=e;printf(%d %d %d %d %dn%.2lfn,x,y,z,u,v,f);return 0;15奇特的分数数列#includeint main() double a=1,b=2,i=1,m=0;for(;i=20;i+)