《C语言程序设计实验与习题指导课后程序设计答案.doc》由会员分享,可在线阅读,更多相关《C语言程序设计实验与习题指导课后程序设计答案.doc(3页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、P18(1)#includeint main(void)int celsius,fahr;fahr=150;celsius=5*fahr/9-5*32/9;printf(fahr=%d,celsius=%dn,fahr,celsius);return 0;(2)#includeint main(void)int celsius,fahr;celsius=26;fahr=9*celsius/5+32;printf(celsius=%d,fahr=%dn,celsius,fahr);return 0;(3)#includeint main(void)int average,math,eng,com
2、p;math=87;eng=72;comp=93;average=(math+eng+comp)/3;printf(math=%d,eng=%d,comp=%d,average=%dn,math,eng,comp,average);return 0;(4)#includeint main(void)int n,a,b,c;n=152;c=n%10;b=(n/10)%10;a=n/100;printf(整数%d的个位数字是%d,十位数字是%d,百位数字是%dn,n,c,b,a);return 0;P27(1)#include#includeint main(void)int celsius,fa
3、hr;printf(Enter celsius:);scanf(%d,&celsius);fahr=9*celsius/5+32;printf(fahr%dn,fahr);return 0;(2)#include#includeint main(void)int money,year;double rate,interest;printf(Enter money,year,rate:);scanf(%d%d%lf,&money,&year,&rate);interest=money*pow(1+rate,year)-money;printf(interest=%.2fn,interest);r
4、eturn 0; (3)#include#includeint main(void)double x,y;printf(Enter x:);scanf(%lf,&x);if(x0)y=pow(x+1,2)+2*x+1/x;elsey=sqrt(x);printf(y=f(%f)=%.2fn,x,y);return 0;(4)#includeint main(void)int x,y;printf(Enter num1:);scanf(%d,&x);printf(Enter num2:);scanf(%d,&y);printf(%d+%d=%dn,x,y,x+y);printf(%d-%d=%d
5、n,x,y,x-y);printf(%d*%d=%dn,x,y,x*y);printf(%d/%d=%dn,x,y,x/y);printf(%d%d=%dn,x,y,x%y);return 0;10的阶乘#includeint main(void)int i,n,product;printf(Enter n:);scanf(%d,&n);product=1;for(i=1;i=n;i+)product=product*i;printf(product=%dn,product);return 0;3 00 ) = * )+; ) ( ) 阶0 )% ,=% )/ % ) ,=% )- %( ) =% ) % ) ) ( ): 0 ) %) )( /*+, ) %(): , 0 ) = ), ) % % ) , , . 0 ) ,% + =) & ) ( , ( . 0 ) , %字 字十,字位%( 0/0%0/0% , ( 0 ) , , % ,% %= / = = = ( 00 ) , = + = , ( 0 ) , % */ 0 = , (