收藏 分销(赏)

河工大C语言课程甘勇课本课后题答案讲义展示省公共课一等奖全国赛课获奖课件.pptx

上传人:精**** 文档编号:3166868 上传时间:2024-06-23 格式:PPTX 页数:20 大小:96.52KB
下载 相关 举报
河工大C语言课程甘勇课本课后题答案讲义展示省公共课一等奖全国赛课获奖课件.pptx_第1页
第1页 / 共20页
河工大C语言课程甘勇课本课后题答案讲义展示省公共课一等奖全国赛课获奖课件.pptx_第2页
第2页 / 共20页
河工大C语言课程甘勇课本课后题答案讲义展示省公共课一等奖全国赛课获奖课件.pptx_第3页
第3页 / 共20页
河工大C语言课程甘勇课本课后题答案讲义展示省公共课一等奖全国赛课获奖课件.pptx_第4页
第4页 / 共20页
河工大C语言课程甘勇课本课后题答案讲义展示省公共课一等奖全国赛课获奖课件.pptx_第5页
第5页 / 共20页
点击查看更多>>
资源描述

1、此此次次PPTPPT制制作作了了C C语语言言程程序序设设计计(第第二二版版)甘甘勇勇主主编编第第四四章章课课后后习题答案程序习题答案程序详细代码详细代码。课后习题课后习题118118全部答案全部答案第1页(1)(1)输入学生成绩,输出不及格率输入学生成绩,输出不及格率#include#include#include#includeint main(void)int main(void)int n,i,l;int n,i,l;double x,fail,sum,average;double x,fail,sum,average;sum=0,l=0;sum=0,l=0;printf(place

2、input students amount:);printf(place input students amount:);scanf(%d,&n);scanf(%d,&n);printf(place input students score:);printf(place input students score:);for(i=0;in;i+)for(i=0;in;i+)scanf(%lf,&x);scanf(%lf,&x);if(x60)if(x60)l+;l+;sum=sum+x;sum=sum+x;average=sum/n;average=sum/n;fail=(l*1.0)/n;fa

3、il=(l*1.0)/n;printf(average=%.2fn,average);printf(average=%.2fn,average);printf(failure=%.2fn,fail);printf(failure=%.2fn,fail);return 0;return 0;第2页(2)(2)输入输入n n个整数,输出其中负数,个整数,输出其中负数,0 0,整数个数,整数个数#include#include#include#includeint main(void)int main(void)int n,i,j,k,l;int n,i,j,k,l;j=0,k=0,l=0;j=0,

4、k=0,l=0;printf(place input digits amount:);printf(place input digits amount:);scanf(%d,&n);scanf(%d,&n);printf(place input digits:);printf(place input digits:);while(n!=0)while(n!=0)n-;n-;scanf(%d,&i);scanf(%d,&i);if(i0)if(i0)j+;j+;else if(i=0)else if(i=0)k+;k+;elseelsel+;l+;printf(0 amount is%dn,k)

5、;printf(0 amount is%dn,k);printf(minus amount is%dn,l);printf(minus amount is%dn,l);printf(positive number amount is printf(positive number amount is%dn,j);%dn,j);return 0;return 0;第3页(3)(3)输入输入n n个整数,输出绝对值最小数个整数,输出绝对值最小数#include#include#include#includeint main(void)int main(void)int n,x,min,i;int n

6、,x,min,i;int x1,x2;int x1,x2;printf(place input digits amount:);printf(place input digits amount:);scanf(%d,&n);scanf(%d,&n);printf(place input the first number:);printf(place input the first number:);scanf(%d,&x2);scanf(%d,&x2);printf(place input digits:);printf(place input digits:);for(i=0;in;i+)f

7、or(i=0;in;i+)scanf(%d,&x);scanf(%d,&x);if(x0)if(xx)if(x2x)min=x1;min=x1;x2=x;x2=x;elseelse if(x2x)if(x2x)min=x;min=x;x2=x;x2=x;printf(min=%dn,min);printf(min=%dn,min);return 0;return 0;第4页(4)(4)输入一个数输入一个数n n,输出,输出1-n1-n全部是全部是7 7或者或者1111倍数,但不一样时是倍数,但不一样时是7 7和和1111倍数倍数#include#include#include#includei

8、nt main(void)int main(void)int n,i;int n,i;printf(place input a digit:);printf(place input a digit:);scanf(%d,&n);scanf(%d,&n);for(i=1;i=n;i+)for(i=1;i=n;i+)if(i%7=0)&(i%11!=0)|(i%7!=0)&(i%11=0)if(i%7=0)&(i%11!=0)|(i%7!=0)&(i%11=0)printf(meet printf(meet the the conditions conditions have:%dn,i);hav

9、e:%dn,i);return 0;return 0;第5页(5)(5)数列:数列:1-1/4+1/7-1/10+1/13-.1-1/4+1/7-1/10+1/13-.求和;求和;#include#include#include#includeint main(void)int main(void)int i,n;int i,n;double sum=0,x=1.0;double sum=0,x=1.0;printf(place input series summation amount:);printf(place input series summation amount:);scanf(

10、%d,&n);scanf(%d,&n);for(i=1;i=n;i+)for(i=1;i=n;i+)sum=sum+1.0/x;sum=sum+1.0/x;x=pow(-1,i)*(3*i+1);x=pow(-1,i)*(3*i+1);printf(sum=%.3fn,sum);printf(sum=%.3fn,sum);return 0;return 0;第6页(6)(6)数列数列:1-2/3+3/5-4/7+5/9-.:1-2/3+3/5-4/7+5/9-.求和;求和;#include#include#include#includeint main(void)int main(void)i

11、nt i,n;int i,n;double sum=0,x,y;double sum=0,x,y;printf(place input series summation amount:);printf(place input series summation amount:);scanf(%d,&n);scanf(%d,&n);for(i=1;i=n;i+)for(i=1;i=n;i+)y=i*1.0;y=i*1.0;x=pow(-1,i+1)*(2*i-1)*1.0;x=pow(-1,i+1)*(2*i-1)*1.0;sum=sum+y/x;sum=sum+y/x;printf(sum=%.

12、3fn,sum);printf(sum=%.3fn,sum);return 0;return 0;第7页(7)(7)计算计算 sin(x)sin(x)前前2020项;项;#include#include#include#includeint main(void)int main(void)int i,j,a;int i,j,a;double sum=0,x1,y1,x,y;double sum=0,x1,y1,x,y;printf(place input a digit:);printf(place input a digit:);scanf(%lf,&x);scanf(%lf,&x);for

13、(i=1;i=20;i+)for(i=1;i=20;i+)a=(2*i-1);a=(2*i-1);x1=(pow(x,a)+0.00001)*1.0;x1=(pow(x,a)+0.00001)*1.0;y1=1.0;y1=1.0;for(j=1;j=a;j+)for(j=1;j=a;j+)y1=y1*j*1.0;y1=y1*j*1.0;y=(pow(-1,i+1)+0.00001)*y1*1.0;y=(pow(-1,i+1)+0.00001)*y1*1.0;sum=x1/y+sum;sum=x1/y+sum;printf(sum=%.3fn,sum);printf(sum=%.3fn,sum)

14、;return 0;return 0;第8页(8)1!+2!+3!+.n!(n=20)(8)1!+2!+3!+.n!(n=20)#include#include#include#includeint main(void)int main(void)int i,sum=0,n,j,y;int i,sum=0,n,j,y;printf(place input max digit:);printf(place input max digit:);scanf(%d,&n);scanf(%d,&n);for(i=1;i=n;i+)for(i=1;i=n;i+)y=1;y=1;for(j=1;j=i;j+

15、)for(j=1;j=i;j+)y=y*j;y=y*j;sum=sum+y;sum=sum+y;printf(sum=%dn,sum);printf(sum=%dn,sum);return 0;return 0;第9页(9)1!+2!+3!+.+m!n,input a digit n,m belong(?,?).(9)1!+2!+3!+.+m!n,input a digit n,m belong(?,?).#include#include#include#includeint main(void)int main(void)int i,sum=0,j,y,n,m;int i,sum=0,j,y

16、,n,m;printf(place input max digit:);printf(place input max digit:);scanf(%d,&n);scanf(%d,&n);for(i=1;i=n;i+)for(i=1;i=n;i+)y=1;y=1;for(j=1;j=i;j+)for(j=1;j=n)if(sum=n)m=i;m=i;break;break;printf(m=%dn,m-1);printf(m=%dn,m-1);return 0;return 0;第10页(10)(10)学生成绩等级;学生成绩等级;#include#include#include#includei

17、nt main(void)int main(void)int i,n;int i,n;double score,max;double score,max;printf(place input students amount:);printf(place input students amount:);scanf(%d,&n);scanf(%d,&n);if(n=0)if(n=0)max=0;max=0;goto loop;goto loop;if(n0)if(n0)printf(place printf(place input input the the first first student

18、 student score:);score:);scanf(%lf,&max);scanf(%lf,&max);printf(place input students score:);printf(place input students score:);while(scanf(%lf,&score),score=0)while(scanf(%lf,&score),score=0)if(maxscore)if(maxscore)max=score;max=score;loop:loop:printf(max=%.1fn,max);printf(max=%.1fn,max);return 0;

19、return 0;第11页(11)*(11)*#include#include#include#includeint main(void)int main(void)int n,a;int n,a;printf(place a digit:);printf(place a digit:);scanf(%d,&n);scanf(%d,&n);while(n!=0)while(n!=0)a=n%10;a=n%10;n=n/10;n=n/10;printf(%d,a);printf(%d,a);printf(n);printf(n);return 0;return 0;第12页(12)(12)最大条

20、约数最大条约数*#include#include#include#includeint main(void)int main(void)int a,b;int a,b;int r;int r;printf(place input a:);printf(place input a:);scanf(%d,&a);scanf(%d,&a);printf(place input b:);printf(place input b:);scanf(%d,&b);scanf(%d,&b);while(r=a%b,r!=0)while(r=a%b,r!=0)a=b;a=b;b=r;b=r;printf(%dn

21、,b);printf(%dn,b);return 0;return 0;第13页(13)*(13)*#include#include#include#includeint main(void)int main(void)int a,b,n,m;int a,b,n,m;int r;int r;printf(place input a:);printf(place input a:);scanf(%d,&a);scanf(%d,&a);m=a;m=a;printf(place input b:);printf(place input b:);scanf(%d,&b);scanf(%d,&b);pr

22、intf(a/b=%d/%dn,a,b);printf(a/b=%d/%dn,a,b);n=b;n=b;while(r=a%b,r!=0)while(r=a%b,r!=0)a=b;a=b;b=r;b=r;printf(a/b=%d/%dn,m/b,n/b);printf(a/b=%d/%dn,m/b,n/b);return 0;return 0;第14页(14)*(14)*#include#include#include#includeint main(void)int main(void)int i,a,n;int i,a,n;int s=0;int s=0;printf(place a d

23、igit(=9):);printf(place a digit(=9):);scanf(%d,&n);scanf(%d,&n);for(i=1;i=n;i+)for(i=1;i=n;i+)a=i;a=i;s=s+pow(a,i);s=s+pow(a,i);printf(s=%dn,s);printf(s=%dn,s);return 0;return 0;第15页(15)*(15)*#include#include#include#includeint main(void)int main(void)int m,n,a,b,c,x;int m,n,a,b,c,x;printf(*input do

24、uble digits all a three digit*n);printf(*input double digits all a three digit*n);printf(place a min digit:);printf(place a min digit:);scanf(%d,&m);scanf(%d,&m);printf(place a max digit:);printf(place a max digit:);scanf(%d,&n);scanf(%d,&n);for(m;m=n;m+)for(m;m=n;m+)a=m%10;a=m%10;b=(m/10)%10;b=(m/1

25、0)%10;c=m/100;c=m/100;x=pow(a,3)+pow(b,3)+pow(c,3);x=pow(a,3)+pow(b,3)+pow(c,3);if(x=m)if(x=m)printf(%d,m);printf(%d,m);printf(n);printf(n);return 0;return 0;第16页(16)*(16)*#include#include#include#includeint main(void)int main(void)int sum1,sum2,x,y,z;int sum1,sum2,x,y,z;for(x=0;x=9;x+)for(x=0;x=9;x

26、+)for(y=0;y=9;y+)for(y=0;y=9;y+)for(z=0;z=9;z+)for(z=0;z=9;z+)sum1=x*100+y*10+z;sum1=x*100+y*10+z;sum2=y*100+z*10+z;sum2=y*100+z*10+z;if(sum1+sum2=532)if(sum1+sum2=532)printf(%d printf(%d%d%d%dn,x,y,z);%dn,x,y,z);return 0;return 0;第17页(17)*(17)*#include#include#include#includeint main(void)int main(

27、void)int i,T,j;int i,T,j;int x;int x;printf(place input test amount:);printf(place input test amount:);scanf(%d,&T);scanf(%d,&T);for(i=1;i=T;i+)for(i=1;i=T;i+)printf(place input test digit:);printf(place input test digit:);scanf(%d,&x);scanf(%d,&x);for(j=2;jx;j+)for(j=2;jx;j+)if(x%j=0)if(x%j=0)print

28、f(no!n);printf(no!n);break;break;else if(x%j!=0)else if(x%j!=0)if(j=x-1)if(j=x-1)printf(yes!n);printf(yes!n);return 0;return 0;第18页(18)*(18)*#include#include#include#includeint main(void)int main(void)int a,b,c,T,i,j,x,y,z;int a,b,c,T,i,j,x,y,z;printf(place input test amount:);printf(place input tes

29、t amount:);scanf(%d,&T);scanf(%d,&T);for(i=0;iT;i+)for(i=0;iT;i+)printf(place input test all digits:);printf(place input test all digits:);scanf(%d%d%d,&a,&b,&c);scanf(%d%d%d,&a,&b,&c);for(j=0;jT;j+)for(j=0;jT;j+)x=(ab)?a:b;x=(ab)?a:b;z=(ab)?a:b;y=c;y=c;if(cx)if(cz)if(cz)y=z;y=z;z=c;z=c;printf(min=%d printf(min=%d amg=%d amg=%d max=%dn,x,y,z);max=%dn,x,y,z);return 0;return 0;第19页谢谢观看假如您以为不错希望能够点赞收藏。第20页

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
百度文库年卡

猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 考试专区 > 中考

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服