C语言程序设计导学第三版参考答案杜友福编.doc

上传人:坚持 文档编号:2100605 上传时间:2019-04-25 格式:DOC 页数:16 大小:111KB
下载 相关 举报
C语言程序设计导学第三版参考答案杜友福编.doc_第1页
第1页 / 共16页
C语言程序设计导学第三版参考答案杜友福编.doc_第2页
第2页 / 共16页
C语言程序设计导学第三版参考答案杜友福编.doc_第3页
第3页 / 共16页
C语言程序设计导学第三版参考答案杜友福编.doc_第4页
第4页 / 共16页
C语言程序设计导学第三版参考答案杜友福编.doc_第5页
第5页 / 共16页
点击查看更多>>
资源描述

1、1C 语言实验(第三版)参考答案实验一3. 程序填空题a 、 b 、 t 4. 程序改错题(1) scanf(“%lf“,c=5.0/9.0*(f-32.0);printf(“f=%lf c=%lfn“,f,c);(2) scanf(“%d“,sum=50*n;printf(“n=%d,s=%dn“,n,s); 5. 程序设计题(1)#include void main()float a,b,c,aver;printf(“Input a b c:“);scanf(“%f%f%f“,aver=(a+b+c)/3.0;printf(“average=%fn“,aver);(2)#include v

2、oid main()float rmb,dollar;printf(“Input rmb:“);scanf(“%f“,dollar=rmb/6.508;printf(“%frmb=%f$n“,rmb,dollar);实验二2. 程序填空题(1)num%10 、 num/100%10 、 g+b=s 2(2)flag=0 、 year%100!=0 、 year%400=0 3. 程序改错题switch(grade)case 10: case 6: printf(“grade=Dn“); break;4. 程序设计题(1)include void main()int x,n;scanf(“%d“

3、,if(x=100000)x=x%100000;if(x=10000)n=5;else if(x=1000)n=4;else if(x=100)n=3;else if(x=10)n=2;else n=1;printf(“%d has %d digitsn“,x,n);switch(n)case 1:printf(“%dn“,x);break;case 2:printf(“%d %dn“,x%10,x/10);break;case 3:printf(“%d %d %dn“,x%10,x/10%10,x/100);break; case 4:printf(“%d %d %d %dn“,x%10,x

4、/10%10,x/100%10,x/1000);break; case 5:printf(“%d %d %d %d %dn“,x%10,x/10%10,x/100%10,x/1000%10,x/10000);break;(2)#include void main()float a,b,c,max;scanf(“%f%f%f“,if(ab)max=a;elsemax=b;3max=maxc?max:c;printf(“max=%gn“,max);实验三2. 程序填空题(1) for(x=50;xvoid main() int a,b,c,d,e;for(a=1;a=0.00001); 4. 程序

5、设计题(1)#include void main() int x,a,b,c;for(x=200;x#include void main()float a,c,fa,f1a,fc;a=88;do fa=5*a*a*a*a*a-8*a*a*a+10*a*a-7*a+25;f1a=25*a*a*a*a-24*a*a+20*a-7;c=a-fa/f1a;fc=5*c*c*c*c*c-8*c*c*c+10*c*c-7*c+25;5a=c;while(fabs(fc)0.0001);printf(“x=%f, y=%fn“,c,fc);实验五2. 程序填空题(1)for(i=0;ivoid main()

6、int i,j,f=0,a34=1,2,3,4,5,6,7,-8,9,10,-11,12;for(i=0;(i#include #define N 10void main()int i,j,s;6/int aN=1,3,5,7,9,11,13,15,17;int aN=17,15,13,11,9,7,5,3,1;scanf(“%d“,i=0;if(a0ai) i+;elsewhile(si;j-)aj=aj-1;aj=s;for(i=0;i#include void main()char str81,c;int i,j;printf(“Input a string:“);gets(str);p

7、rintf(“Input a char:“);c=getchar();for(i=0;stri!=0;i+)if(stri=c)for(j=i;j#include void main()char str81,substr81;int i,n=-1;printf(“Input a string:“);gets(str);printf(“Input a substring:“);gets(substr);for(i=0;stri!=0;i+)for(k=0;substrk=stri+k;k+) if(substrk+1=0) n=i;break; printf(“n=%dn“,n);实验七2. 程

8、序填空题n-1 、 aj+1 、 aj+1 、 s 3. 程序改错题int leap(int year)flag=flag|(year%400=0); if(leap(y)=1) 4. 程序设计题(1)#include int isprime(int); void main()int x,s=0;for(x=200;xvoid sort(int a,int n) int i,j,k,t;for(i=0;i=0 if(i=j)return;elset=si;si=sj;sj=t;fun(s,i+1,j-1);void main()char str81;gets(str);fun(str,0,st

9、rlen(str)-1);puts(str);(2)/sy8proc2.c#include #include extern double newx(double a,double b);double f(double x)double y;y=2*x*x*x-3*x*x+7*x-13;return (y);void main()double a,b,x;do10printf(“Please input a,b:“);scanf(“%lf,%lf“,while(f(a)*f(b)0);dox=newx(a,b);if(f(a)*f(x)0)x=newx(x,b);elsex=newx(a,x);while(fabs(f(x)0.00001);printf(“x=%lf,y=%lfn“,x,f(x);/sy8newx2.cdouble newx(double a,double b)/或 extern double newx(double a,double b)double xnew;xnew=(a*f(b)-b*f(a)/(f(b)-f(a);return (xnew);实验九2. 程序填空题(1)p=a 、 *(*p+j) 注:外循环改为:for(i=0;ivoid fun(char *pp) int i,n=0;while(*(pp+n)=*)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 试题真题

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。