问答题

请编写函数fun(),其功能是计算并输出下列多项式值 Sn=1+1/1!+1/2!+1/3!+1/4!+…+1/n! 例如:从键盘输入15,则输出为s=2.718282。 注意;部分源程序以存在文件test37_2.cpp中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 文件test37_2.cpp的内容如下: #include<stdio.h> #include<iostream.h> double fun(int n) { } void main ( ) { int n; double s; cout<<"Input n:"<<end1; cin>>n; s=fun(n); cout<<"s="<<s<<end1; }

【参考答案】

double fun(int n) { double t,sn=1.0; int i,j; for(i=1;i<=n;i......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)