#include <iostream> #include "OJ.h" using namespace std; /* void GetResult(int InputNum, double *NumResult); 输入参数: Int InputNum:输入一个正整数,进行表达式计算 char *NumResult:输出表达式的值 返回值: void */ double fact(unsigned int k ) { double sum =1.0; for (unsigned int i = 1; i <= k ; ++i) { sum *= i; } return sum; } void GetResult(int InputNum, double *NumResult) { for (int i = 1; i <= InputNum; ++i) { *NumResult += 1.0/ fact(i); } return ; } int main() { int InputNum = 5; double NumResult = 0; GetResult(InputNum, &NumResult); cout<<NumResult<<endl; return 0; }
时间: 2024-10-07 14:18:07