[Huawei Machine Test exercises]51. Series summation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.