解题思路:
两个函数都用递归
注意事项:
无
参考代码:
#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 人评分
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:532 |
A+B for Input-Output Practice (VII) (C++代码)浏览:635 |
哥德巴赫曾猜测 (C语言代码)浏览:1093 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:500 |
众数问题 (C语言代码)浏览:888 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:604 |
母牛的故事 (C语言代码)浏览:1446 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:639 |
蚂蚁感冒 (C语言代码)浏览:804 |
勾股数 (C语言代码)浏览:823 |