欢迎来到天天文库
浏览记录
ID:38708700
大小:93.50 KB
页数:16页
时间:2019-06-18
《华北电力大学c++实验指导函数的应用习题参考答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验指导函数的应用习题解答1.改错题见文件“实验指导改错题习题解答”。2.填空题(在空白处填入适当内容,将程序补充完整,并上机调试)(1)请补充fun函数,该函数的功能是判断一个数的个位数字和百位数字之和是否等于其十位上的数字,如果为“是”,则返回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;cin>>num;if(fun(num)==1)cout<<"yes"<2、;elsecout<<"no"<voidmain(){intSunFun(int);cout<<"sum="<doublefun(intn){inti;floatsum=0.0;for(i=1;i<=n;i++)if(i%3==03、4、i%7==5、0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<doublefun(intn){inti;floatsum=0.0;for(i=1;i<=n;i++)if(i%3==06、7、i%7==0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<8、}(4)题略#includedoublef(intn){inti;longs;s=1;for(i=1;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);cout<doublefun(doubleq){intn;doubles;n=2;s=2.0;while(s<=q){s=s+(n+1.0)/n;n++;}returns;}voidmain(){cout<9、)<intc1,c2,c3;voidfun(longn){c1=c2=c3=0;while(n){switch(n%10){case1:c1++;break;case2:c2++;break;case3:c3++;break;}n=n/10;}}voidmain(){longn=123114350;fun(n);cout<<"c1="<#includedoublef(doublex){i10、f(fabs(x-0.0)<1e-611、12、fabs(x-2.0)<1e-6)return0;elseif(x<0)return(x-1)/(x-2);elsereturn(x+1)/(x-2);}doublefun(intn){inti;doubles=0.0,y;for(i=-n;i<=n;i++){y=f(1.0*i);cout<doublefun(intn){inti,j;doublesum=0.0,t;for(j=113、;j<=n;j++){t=0.0;for(i=1;i<=j;i++)t+=i;sum+=1/t;}returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<#includeunsignedfun(unsignedw){unsignedn,k
2、;elsecout<<"no"<voidmain(){intSunFun(int);cout<<"sum="<doublefun(intn){inti;floatsum=0.0;for(i=1;i<=n;i++)if(i%3==0
3、
4、i%7==
5、0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<doublefun(intn){inti;floatsum=0.0;for(i=1;i<=n;i++)if(i%3==0
6、
7、i%7==0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<
8、}(4)题略#includedoublef(intn){inti;longs;s=1;for(i=1;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);cout<doublefun(doubleq){intn;doubles;n=2;s=2.0;while(s<=q){s=s+(n+1.0)/n;n++;}returns;}voidmain(){cout<9、)<intc1,c2,c3;voidfun(longn){c1=c2=c3=0;while(n){switch(n%10){case1:c1++;break;case2:c2++;break;case3:c3++;break;}n=n/10;}}voidmain(){longn=123114350;fun(n);cout<<"c1="<#includedoublef(doublex){i10、f(fabs(x-0.0)<1e-611、12、fabs(x-2.0)<1e-6)return0;elseif(x<0)return(x-1)/(x-2);elsereturn(x+1)/(x-2);}doublefun(intn){inti;doubles=0.0,y;for(i=-n;i<=n;i++){y=f(1.0*i);cout<doublefun(intn){inti,j;doublesum=0.0,t;for(j=113、;j<=n;j++){t=0.0;for(i=1;i<=j;i++)t+=i;sum+=1/t;}returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<#includeunsignedfun(unsignedw){unsignedn,k
9、)<intc1,c2,c3;voidfun(longn){c1=c2=c3=0;while(n){switch(n%10){case1:c1++;break;case2:c2++;break;case3:c3++;break;}n=n/10;}}voidmain(){longn=123114350;fun(n);cout<<"c1="<#includedoublef(doublex){i
10、f(fabs(x-0.0)<1e-6
11、
12、fabs(x-2.0)<1e-6)return0;elseif(x<0)return(x-1)/(x-2);elsereturn(x+1)/(x-2);}doublefun(intn){inti;doubles=0.0,y;for(i=-n;i<=n;i++){y=f(1.0*i);cout<doublefun(intn){inti,j;doublesum=0.0,t;for(j=1
13、;j<=n;j++){t=0.0;for(i=1;i<=j;i++)t+=i;sum+=1/t;}returnsum;}voidmain(){intn;doubles;cout<<"Inputn:";cin>>n;s=fun(n);cout<<"s="<#includeunsignedfun(unsignedw){unsignedn,k
此文档下载收益归作者所有