填空题 以下程序中,成员函数fun1的功能是;当n为偶数时,调用函数even2求x=l/2+1/4+...+l/n;当n为奇数时,调用函数odd3求x=l/l+l/3+...+l/n。函数fact4的功能是计算y=1!+2!+3!+…+n!的值。 【程序】(4分) #include class A{ float x,y; int n; public; A(int m){n=m;} float even5 { float s=0.5; if(n==2) return (s); for (int i=4; i<=n; i+=2) 6(23) 7; return (s); } float odd8{ float s=l; if(n==1)return s; for (int i=3; i<=n; 9(24) 10 ) s+=1.0/i; return (s); } void fact11 { float fa=1; y=l; for (int i=2; i<=n; i++){ 12(25) 13 ; 14(26) 15 ; } } void fun16 { if (n%2) x=odd17; else x=even18; } void print19{cout<<"n="<20; a2.fun21; a1.fact22; a2.fact23; a1.print24; a2.print25; }
【正确答案】
【答案解析】