欢迎来到天天文库
浏览记录
ID:46678069
大小:161.53 KB
页数:15页
时间:2019-11-26
《华北电力大学c++实验指导函数的应用习题参考答》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验指导函数的应用习题解答1.改错题见文件“实验指导改错题习题解答”。2.填空题(在空白处填入适当内容,将程序补充完整,并上机调试)(1)请补充fim函数,该函数的功能是判断一个数的个位数字和百位数字Z和是否等于其I•位上的数字,如果为“是”,则返回1;为“否”,则返回0。#includeintfun(intn){intg,s,b;g=n%10;s=n/10%10;b=n/100;if(g+b==s)return1;elsereturn0;}voidmain(){intnum
2、;cin»num;if(fun(num)==l)cout«uyesH«endl;elsecout«unoM«endl;}(2)题略#includevoidmain(){intSunFun(int);cout«Msum=n«SunFun(10)«endl;}intSunFun(intn){intF(int);intx,s=0;for(x=0;x<=n;x++)s+=F(x);returns;}intF(intx)return(x*x+l);(2)题略#include3、eam.h>doublefun(intn){inti;floatsum=0.0;for(i=l;i<=n;i++)if(i%3==0lli%7==0)sum+=l.0/i;returnsum;}voidmain(){intn;doubles;cout«HInputn:M;cin»n;s=fun(n);cout«Hs=n<doublefun(intn){inti;floatsum=0.0;for(i=l;i<=n;i++)if(i%34、==0lli%7==0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout«nInputn:n;cin»n;s=fun(n);cout«ns=°«s«endl;1(2)题略#includedoublef(intn){inti;longs;s=l;for(i=l;i<=n;i++)s=s*i;returns;)voidmain(){longs;intk,n;cin»n;s=0;for(k=0;k<=n;k++)s=s+f(k);5、cout«s«endl;}(3)题略#includedoublefun(doubleq){intn;doubles;n=2;s=2.0;while(s<=q){s=s+(n+1.0)/n;n++;}returns;)voidmain(){cout«fun(50)«endl;}(1)题略#includeintcl,c2,c3;voidfun(longn){cl=c2=c3=0;while(n){switch(n%10){casel:cl++;break;6、case2:c2++;break;case3:c3++;break;n=n/10;voidmain(){longn=123114350;fun(n);cout«Mc1="«c1«"c2="«c2«"c3=H«c3«endl;}(2)题略#include#includcdoublef(doublex){if(fabs(x-0.0)7、turn(x+l)/(x・2);}doublefun(intn){inti;doubles=0.0,y;ft)r(i=-n;i<=n;i++)(y=f(1.0*i);cout«y«endl;s+=y;}returns;}voidmain(){cout«fun(5)«endl;}(1)题略#includedoublefun(intn){doublesum=0.0,t;for(j=l;j<=n;j++){t=0.0;for(i=l;i<=j;i++)t+=i;sum+=l/t;r8、eturnsum;voidmain(){intn;doubles;cout«HInputn:H;cin»n;s=fun(n);coutvvfvvsvvendl;}(2)略(3)略1.按要求编写下列程序,并上机调试运行1.程序如下:#include#includeunsignedfun(unsignedw){unsignedn,k;n=0;k=w;while(w>IO)〃循环结束,n中为w的位数-I{n++;w=w/10;}ret
3、eam.h>doublefun(intn){inti;floatsum=0.0;for(i=l;i<=n;i++)if(i%3==0lli%7==0)sum+=l.0/i;returnsum;}voidmain(){intn;doubles;cout«HInputn:M;cin»n;s=fun(n);cout«Hs=n<doublefun(intn){inti;floatsum=0.0;for(i=l;i<=n;i++)if(i%3
4、==0lli%7==0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout«nInputn:n;cin»n;s=fun(n);cout«ns=°«s«endl;1(2)题略#includedoublef(intn){inti;longs;s=l;for(i=l;i<=n;i++)s=s*i;returns;)voidmain(){longs;intk,n;cin»n;s=0;for(k=0;k<=n;k++)s=s+f(k);
5、cout«s«endl;}(3)题略#includedoublefun(doubleq){intn;doubles;n=2;s=2.0;while(s<=q){s=s+(n+1.0)/n;n++;}returns;)voidmain(){cout«fun(50)«endl;}(1)题略#includeintcl,c2,c3;voidfun(longn){cl=c2=c3=0;while(n){switch(n%10){casel:cl++;break;
6、case2:c2++;break;case3:c3++;break;n=n/10;voidmain(){longn=123114350;fun(n);cout«Mc1="«c1«"c2="«c2«"c3=H«c3«endl;}(2)题略#include#includcdoublef(doublex){if(fabs(x-0.0)7、turn(x+l)/(x・2);}doublefun(intn){inti;doubles=0.0,y;ft)r(i=-n;i<=n;i++)(y=f(1.0*i);cout«y«endl;s+=y;}returns;}voidmain(){cout«fun(5)«endl;}(1)题略#includedoublefun(intn){doublesum=0.0,t;for(j=l;j<=n;j++){t=0.0;for(i=l;i<=j;i++)t+=i;sum+=l/t;r8、eturnsum;voidmain(){intn;doubles;cout«HInputn:H;cin»n;s=fun(n);coutvvfvvsvvendl;}(2)略(3)略1.按要求编写下列程序,并上机调试运行1.程序如下:#include#includeunsignedfun(unsignedw){unsignedn,k;n=0;k=w;while(w>IO)〃循环结束,n中为w的位数-I{n++;w=w/10;}ret
7、turn(x+l)/(x・2);}doublefun(intn){inti;doubles=0.0,y;ft)r(i=-n;i<=n;i++)(y=f(1.0*i);cout«y«endl;s+=y;}returns;}voidmain(){cout«fun(5)«endl;}(1)题略#includedoublefun(intn){doublesum=0.0,t;for(j=l;j<=n;j++){t=0.0;for(i=l;i<=j;i++)t+=i;sum+=l/t;r
8、eturnsum;voidmain(){intn;doubles;cout«HInputn:H;cin»n;s=fun(n);coutvvfvvsvvendl;}(2)略(3)略1.按要求编写下列程序,并上机调试运行1.程序如下:#include#includeunsignedfun(unsignedw){unsignedn,k;n=0;k=w;while(w>IO)〃循环结束,n中为w的位数-I{n++;w=w/10;}ret
此文档下载收益归作者所有