资源描述:
《c语言程序设计课后答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C语言程序设计课后习题习题21:#includeintmain(void){intnum1,num2;printf("inputnum1,num2:");scanf("%d%d",&num1,&num2);printf("num1+num2=%d",num1+num2);printf("num1*num2=%d",num1*num2);printf("num1/num2=%d",num1/num2);return0;}2:#includeintmain(void){doublesum;doublea;print
2、f("请输入用电量:");scanf("%lf",&a);if(a>0&&a<=50){sum=0.53*a;}else{sum=0.05*a;}printf("用电量为%.2f",sum);return0;}3:#includeintmain(void){doublex;inti,a,b,n;printf("输入实数x:");scanf("%lf",&x);printf("输入正整数n:");scanf("%d",&n);a=1;for(i=1,b=x;i<=n;i++){x=a*b;a=x;}printf("x^n=%.1f",
3、x);return0;}4:#include#includeintmain(void){intm,n,i;doublesum,item;printf("Enterm:");scanf("%d",&m);printf("Entern:");scanf("%d",&n);sum=0;for(i=m;i<=n;i++){item=pow(i,2)+1.0/i;sum=sum+item;}printf("sum=%.3f",sum);return0;}5:#includeintmain(void){inti,n,f
4、lag,num,denominator;doublesum,item;printf("entern:");scanf("%d",&n);sum=0,flag=1,denominator=1,num=1;for(i=1;i<=n;i++){item=flag*num*1.0/denominator;sum=sum+item;flag=-flag;num=num+1;denominator=denominator+2;}printf("sum=%.2f",sum);return0;}6:#include#includeint
5、main(void){intmonth,years;doublemoney,loan,rate;printf("enterloan:");scanf("%lf",&loan);printf("enterrate:");scanf("%lf",&rate);printf("yearsmoney");for(years=5;years<=30;years++){money=loan*rate*pow((1+rate),(years*12))/(pow((1+rate),(years*12))-1);printf("%d%10.2f",years,mone
6、y);}return0;}7:#include#includeintmain(void){intn,i;doubledata,sum;printf("输入正整数n:");scanf("%d",&n);sum=0;for(i=1;i<=n;i++){data=pow(2,i);sum=sum+data;}printf("sum=%.1f",sum);return0;}8:#includedoublefact(intn);intmain(void){inti,n;doublee,data;printf("输
7、入正整数n:");scanf("%d",&n);e=0;for(i=0;i<=n;i++){data=fact(i);e=e+data;}printf("e=%.2f",e);return0;}doublefact(intn){inti;doubleproduct;product=1;for(i=1;i<=n;i++){product=product*i;}returnproduct;}习题31:#include#includeintmain(void){floata,b,c;doublearea,perimeter,s
8、;printf("entera,b,c.:");sc