资源描述:
《华农c语言教材习题参考答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、注:答案仅供参考分期还款:#include#includeintmain(){doubled,p,r;scanf("%lf%lf%lf",&d,&p,&r);printf("%.1f",log10(p/(p-d*r))/log10(1+r));return0;}计算分段函数函数值:#includeintmain(){doublex;scanf("%lf",&x);if(x<1)printf("%.2f",x);elseif(x>=1&&x<10)printf("%
2、.2f",2*x-1);elseprintf("%.2f",3*x-11);}成绩等级评分:#include#includeintmain(){intscore;scanf("%d",&score);if(score>100
3、
4、score<0)printf("error");elseif(score>=90)printf("A");elseif(score>=80)printf("B");elseif(score>=70)printf("C");elseif(score>=60)p
5、rintf("D");elseprintf("E");return0;}1320秒后时间:#include#includeintmain(){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#inc
6、ludeintmain(){doubled,p,r;scanf("%lf%lf%lf",&d,&p,&r);if(d==0)printf("0.0");elseif(d*(1+r)-p>d)printf("God");else{printf("%.1f",log10(p/(p-d*r))/log10(1+r));}return0;}字母分类统计:#include13#includeintmain(){charch;intnL=0,nN=0,nS=0,nO=0
7、;while((ch=getchar())!=''){if(ch>='a'&&ch<='z'
8、
9、ch>='A'&&ch<='Z')nL++;elseif(ch>='0'&&ch<='9')nN++;elseif(ch=='')nS++;elsenO++;}printf("%d%d%d%d",nL,nN,nS,nO);return0;}计算数列和:#includemain(){inti,n;doublea=2,b=1,s=0;scanf("%d",&n);for(i=1;i<=n;i++){
10、s=s+a/b;a=a+b;b=a-b;}printf("%.4f",s);}自由落体:#include#includeintmain(){doublesum=-100,d=100;inti,n;scanf("%d",&n);for(i=1;i<=n;i++){13sum+=2*d;d/=2;}printf("%.3f%.3f",sum,d);return0;}迭代法求平方根:#include#includeintmain(){doublea,
11、x0,x1=1;scanf("%lf",&a);do{x0=x1;x1=1.0/2*(x1+a/x1);}while(fabs(x1-x0)>=1e-5);printf("%.4lf",x1);return0;}打印三角形:#include#defineabs(x)((x)>=0?(x):-(x))intmain(){intn,i,j;scanf("%d",&n);for(i=-(n-1);i<=(n-1);i++){for(j=0;j12、0;j#include13intmain(){inti,j,k,n;scanf("%d",&n);for(i=1;i<=n;i++)for(j=i;j<=n;j++){k=(int)sqrt(i*i+j*