淘豆网
1/15
0/100
您的浏览器不支持进度条
更多>>该用户其他文档
下载所得到的文件列表
华北电力大学c实验指导函数的应用习题参考答案.doc
文档介绍:
华北电力大学c实验指导函数的应用习题参考答案.doc实验指导函数的应用习题解答改错题见文件“实验指导改错题习题解答”。填空题(在空白处填入适当内容,将程序补充完整,并上机调试)请补充fim函数,该函数的功能是判断一个数的个位数字和百位数字Z和是否等于其I•位上的数字,如果为“是”,则返回1;为“否”,则返回0。#include<iostream.h>intfun(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)==l)cout«uyesH«endl;elsecout«unoM«endl;}题略#include<iostream.h>voidmain(){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)题略#include<iostream.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<<s«endl;}题略#include<iostream.h>doublefun(intn){inti;floatsum=0.0;for(i=l;i<=n;i++)if(i%3==0lli%7==0)sum+=1.0/i;returnsum;}voidmain(){intn;doubles;cout«nInputn:n;cin»n;s=fun(n);cout«ns=°«s«endl;1题略#include<iostream.h>doublef(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);cout«s«endl;}题略#include<iostream.h>doublefun(doubleq){intn;doubles;n=2;s=2.0;while(s<=q){s=s+(n+1.0)/n;n++;}returns;)voidmain(){cout«fun(50)«endl;}题略#include<iostream.h>intcl,c2,c3;voidfun(longn){cl=c2=c3=0;while(n){switch(n%10){casel:cl++;break;case2:c2++;break;case3:c3++;break;n=n/10;voidmain(){longn=123114350;fun(n);cout«Mc1="«c1«"c2="«c2«"c3=H«c3«endl;}题略#include<iostream.h>#includc<malh.h>doublef(doublex){if(fabs(x-0.0)<le-6llfabs(x-2.0)<le-6)return0;elseif(x<0)return(x-l)/(x-2);elsereturn(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;}题略#include<iostream.h>doublefun(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;returnsum;voidmain(){intn;doubles;cout«HInputn:H;cin»n;s=fun(n);coutvvfvvsvvendl;}略略按要求编写下列程序,并上机调试运行程序如下:#include<iostream.h>#include<math.h>unsignedfun(unsignedw){unsignedn,k;n=0;k=w;while(w>IO) 〃循环结束,n中为w的位数-I{n++;w=w/10;}returnk%(int)p 内容来自淘豆网www.taodocs.com转载请标明出处.