Dream1018


私信TA

用户名:18924961396

访问量:2699

签 名:

等  级
排  名 2317
经  验 2272
参赛次数 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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区