欢迎来到天天文库
浏览记录
ID:20360706
大小:355.58 KB
页数:8页
时间:2018-10-10
《c语言程序设计实验五参考答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验5函数(1)参考答案5-1、以下程序的功能:从键盘输入两个数,计算出他们的和,并将结果输出在屏幕上。调试运行程序,观察出现了什么错误,提出修改方案。答案:#includevoidmain(){floatadd(floatx,floaty);floata,b,c;scanf('’%f,%f',&a,&b);c=add(a,b);printf("sumis%f’’,c);}floatadd(floatx,floaty){floatz;z=x+y;return(z);}氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺氺糸氺氺氺氺氺氺氺氺氺糸氺糸氺氺氺糸
2、氺氺氺氺氺:{c氺:{c氺:{c氺:{c氺:{c氺:氺:氺:氺:{c氺:氺:{c氺本氺本氺本氺本氺本氺本氺本实验二<f**f*#T>#T%#T%#T%#T%#T%#T%<、#T%<、#T%<、#T%<、#T%<、#T%<、^T%5-2、以T程序的功能:输出3—1000之间的素数。选择合适的内容填入空白处,并调试运行程序。答案:#includevoidmain(){inti,j,num=0;for(i=3;i<=1000;i++){for(j=2;j<=1000;j++)if(i%2=0)break;if(i%2!=0){printf(n%5d",i
3、);num++;if(num%10==0)printf(n'.);printf("n);1111113579333331357955555135797777713579111ii246801O--Q-999135791031051071091111131151171191211231251271291311331351371391411431451471491511531551571591G1203205207209211213215217219221223225227229231233235237239241243245247249251253255257
4、2592612632652672692712732752772792812832852872892912932952972993013233253273293313333353373393413033053073093113133153173193211831851871891911931951971992011631651671691711731751771791813433453473493513633653673693713833853873893914034054074094114234254274294314434454474494513533553573
5、59361373375377379381393395397399401413415417419421433435437439441453455457459461463465467469471473475477479481483485487489491493495497499501-1^1x
6、«f>rTwrTwrTwrTwrTwrT*rT*rT*rT*rT*rT*»T>rT*rTwrT*rTwrT*rTwrT*rTwrT*rTwrTwrTwrTwrTwrTw»T>rTwrTwrTwrTwrTwrTwrTwrTwrTwrTwrTwrTwrTwrTwrTwrTwr7wrT
7、wr7wrTwr7wrTwr7wrTwr7wrTwr7wrTwr7wrTwr7wrTwr7wrTwr7wrTwr7wrTwrlwrTw*•黔fJ/,Jwry,rjwrjwrjwrj^rjwrj^rjwrjwrjwrj*rjwrj*rjwrj«rjwrj*rjwrj«rjw,J,rfw,J,rfwrj«,Jw,J,rfwrj*、’J
8、,J,,J,rj«,Jw,J,,Jw,J,rfw,J,*Jw,J,*Jw,J,*Jw,J,巧,,J,r^,,J,巧,,J,巧,,J,r^,,J,巧,,J,,J,r^,,J,巧,,J,r^,,J,巧,,J,,J,,J,,J,为-皿—计算n的
9、立方,并将结果输出在屏幕上。要求计算n的立5-3、从键盘上输入一个整数n,方用函数实现。答案:#includevoidmain(){inta;intsum(intn);printf(ni叩utn:’’);scanf("%d”,&a);sum(a);printf(',n*n*n=%d,',sum(a));}intsum(intn){intb;b=n*n*n;returnb;运行结果:Jgj2«f#«f>«f>«f><7wr
此文档下载收益归作者所有