Dream1018


私信TA

用户名:18924961396

访问量:2735

签 名:

等  级
排  名 2376
经  验 2275
参赛次数 0
文章发表 9
年  龄 1
在职情况 学生
学  校
专  业

  自我简介:

不负韶华

解题思路:

两个函数都用递归

注意事项:



参考代码:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double fact(int n)

{

    if(n==1) return 1.0;

    else return fact(n-1)*n;


}

double mypow(double x,int n)

{

    if(n==1) return x;

    else return x*mypow(x,n-1);

}


int main()

{

    float x;

    int n;

    float sum=0;

    scanf("%f %d",&x,&n);

    for(int i=1;i<=n;i++)

    {

        sum+=pow(-1.0,i+1)*mypow(x,i)/fact(i);

    }

    printf("%.4f",sum);

    return 0;

}


 

0.0分

1 人评分

  评论区