资源描述:
《C语言课后习题.docx》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、习题第三章#include#includeintmain(){intd,p;doubler,a,m;scanf("%d%d%lf",&d,&p,&r);a=(p/(p-d*r));m=log(a)/log(1+r);if(p>0&&d>0){if(d<=m*p)printf("%.1f",m);elseprintf("God");}elseprintf("0.0");return0;}勾股数#includeintmain(){inta,b,c,n
2、;scanf("%d",&n);for(a=1;a<=n;a++){for(b=1;b<=n;b++){for(c=1;c<=n;c++){if(c*c==a*a+b*b){if(a<=b){printf("%d%d%d",a,b,c);}}}}}return0;}第四章计算分段函数值#includeintmain(){floatx,y;scanf("%f",&x);if(x<1)y=x;elseif(x>=1&&x<10)y=2*x-1;elseif(x>=10)y=3*x
3、-11;printf("%.2f",y);return0;}找出三个数中最大的数#includeintmain(){inta,b,c,max;scanf("%d%d%d",&a,&b,&c);max=a>b?a:b;if(c>max)max=c;printf("%d",max);return0;}10844成绩等级评分#includeintmain(){intx;scanf("%d",&x);if(x>=0&&x<=100){switch(x/10){case1
4、0:case9:printf("A");break;case8:printf("B");break;case7:printf("C");break;case6:printf("D");break;default:printf("E");break;}}elseprintf("error");return0;}前续和后续字符#includeintmain(){charx;x=getchar();switch(x){case'0':printf("first");printf("%c
5、",x+1);break;case'9':printf("%c",x-1);printf("last");break;case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':printf("%c",x-1);printf("%c",x+1);break;default:printf("error");break;}return0;}20秒后的时间#include#includeintmai
6、n(){inth,m,s;scanf("%d:%d:%d",&h,&m,&s);s=s+20;if(s>59){s=s%60;m++;if(m>59){m=m%60;h++;if(h>23)h=0;}}printf("%02d:%02d:%02d",h,m,s);return0;}分期还款#include#includeintmain(){intd,p;doubler,a,m;scanf("%d%d%lf",&d,&p,&r);a=(p/(p-d*r));m=
7、log(a)/log(1+r);if(p>0&&d>0){if(d<=m*p)printf("%.1f",m);elseprintf("God");}elseprintf("0.0");return0;}第五章字母分类统计#include#includeintmain(){charch;inta=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0;while((ch=getchar())!=''){if(ch<=127&&ch>=123)a
8、++;elseif(ch>=97&&ch<=122)b++;elseif(ch<=96&&ch>=91)c++;elseif(ch<=90&&ch>=65)d++;elseif(ch>=58&&ch<=64)e++;elseif(ch>=48&&ch<=57)f++;elseif(ch>=33&&ch<=47)g++;elseif(ch==32)h++;elsei++;}printf("%d%d%d%d",d+b,f,h,a+c+e+g+i);}水仙花数#include