求f(x,n)(递归)

描述

已知

enter image description here

用递归函数求解。

格式

输入格式

第一数是x的值,第二个数是n的值。

输出格式

函数值,保留两位小数。

样例

输入样例

1 2

输出样例

0.40

限制

时间限制: 1000 ms

内存限制: 65536 KB

注意:int转为double

#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;

double fb(double x, double n){
	if (n == 1) {
		return x*1.0/(1+x)*1.0;        //装换
	} else {
		return x*1.0/(n+fb(x, n-1));
	}
}

int main ()
{
	double n, x;
	double ans;
	scanf ("%lf %lf", &x, &n);
	ans = fb(x, n);
	printf ("%.2lf", ans);
	return 0;
}
发布了89 篇原创文章 · 获赞 77 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/wodemaoheise/article/details/104623799