Topic
Descriptive narrative:
Topic Description Narration
编敲代码,输入一个正整数n。求下列算式的值。要求定义和调用函数fact(k)计算k的阶乘。
1+1/2!+ .... +1/n!计算结果保存在double类型变量中。
Interface description
Prototype:
void GetResult(int InputNum, double *NumResult);
Enter the number of references:
Int InputNum:输入一个正整数,进行表达式计算char *NumResult:输出表达式的值
return value:
void
Practice Stage: 0 Basics
Code
/* ---------------------------------------* Date: 2015-07-04* sjf0115* title: Series Summation * Source: Huawei Machine Test Exercises------------------------ -----------------*/#include <iostream>#include "OJ.h"using namespace STD;//int overflowDoubleFactintK) {Doubleresult =1; for(inti =1; i<=k;i++) {result *=i; }//for returnResult;}/*void getresult (int inputnum, double *numresult); input parameter: int Inputnum: Enter a positive integer. Perform expression evaluation char *numresult: Output expression value return value: void*/voidGetResult (intInputnum,Double*numresult) {DoubleTMP, sum =0.0; for(inti =1; I <= inputnum;i++) {tmp =1.0/fact (i); sum + = tmp; }//for*numresult = sum; }
[Huawei Machine Test exercises]51. Series summation