资源描述:
《C语言程序设计实验与习题指导课后程序设计答案.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、P18(1)#includeintmain(void){intcelsius,fahr;fahr=150;celsius=5*fahr/9-5*32/9;printf("fahr=%d,celsius=%d",fahr,celsius);return0;}(2)#includeintmain(void){intcelsius,fahr;celsius=26;fahr=9*celsius/5+32;printf("celsius=%d,fahr=%d",celsius,fahr);
2、return0;}(3)#includeintmain(void){intaverage,math,eng,comp;math=87;eng=72;comp=93;average=(math+eng+comp)/3;printf("math=%d,eng=%d,comp=%d,average=%d",math,eng,comp,average);return0;}(4)#includeintmain(void){intn,a,b,c;n=152;c=n%10;b=(n/10)%10;
3、a=n/100;printf("整数%d的个位数字是%d,十位数字是%d,百位数字是%d",n,c,b,a);return0;}P27(1)#include#includeintmain(void){intcelsius,fahr;printf("Entercelsius:");scanf("%d",&celsius);fahr=9*celsius/5+32;printf("fahr%d",fahr);return0;}(2)#include#include4、th.h>intmain(void){intmoney,year;doublerate,interest;printf("Entermoney,year,rate:");scanf("%d%d%lf",&money,&year,&rate);interest=money*pow(1+rate,year)-money;printf("interest=%.2f",interest);return0;}(3)#include#includeintmain(void){doublex,y;p
5、rintf("Enterx:");scanf("%lf",&x);if(x<0){y=pow(x+1,2)+2*x+1/x;}else{y=sqrt(x);}printf("y=f(%f)=%.2f",x,y);return0;}(4)#includeintmain(void){intx,y;printf("Enternum1:");scanf("%d",&x);printf("Enternum2:");scanf("%d",&y);printf("%d+%d=%d",x,y,x+y);print
6、f("%d-%d=%d",x,y,x-y);printf("%d*%d=%d",x,y,x*y);printf("%d/%d=%d",x,y,x/y);printf("%d%%%d=%d",x,y,x%y);return0;}10的阶乘#includeintmain(void){inti,n,product;printf("Entern:");scanf("%d",&n);product=1;for(i=1;i<=n;i++){product=product*i;}printf("prod
7、uct=%d",product);return0;}