C语言Matrix编程题——[Recursion]D. Liang 8.5 Summing series

[Recursion]D. Liang 8.5 Summing series

Description:

用递归函数计算以下等式m(i) = 1/3 + 2/5 + 3/7 + 4/9 + 5/11 + 6/13 + … + i/(2i+1)
使用以下函数头
double m(int i)

Input:

正整数n(n<=100)

Output :

输出m(n),结果保留两位小数

Sample Input:

1

Sample Output:

0.33

Hint:

Don’t submit the main() function.

Programme:

//Date:2020/6/12
//Author:Kamenrider Justice
double m(int n)
{
   if(n==1)
   {
      return 1.0/3.0;
   }
   else
   {
      return m(n-1)+(double)n/(2*n+1);
   }
}

数据结构核心原理与算法应用

你可能感兴趣的:(C语言Matrix)