单点时限: 2.0 sec
内存限制: 512 MB
Write a RECURSIVE function to compute the following formula:
$sum(n) = 1 - \frac{1}{2} + \frac{1}{3} – \frac{1}{4} + … -(-1)^n*\frac{1}{n}$
/***************************************************************/
/* */
/* DON'T MODIFY main function ANYWAY! */
/* */
/***************************************************************/
#include <stdio.h>
double sum(int n)
{
// TODO: your function definition
}
int main()
{
int n;
scanf("%d",&n);
printf("%f\n",sum(n));
return 0;
}
29358
0.693130
1
1.000000
3
0.833333