#include
int main()
{
int n,i;
double sum=0;
printf("请输入n = ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2) sum+=(double)1/i;
else sum-=(double)1/i;
}
printf("结果为:%0.6lf\n",sum);
system("pause");
return 0;
}
#include "stdio.h"
float fun(int n)
{ if(n==1)
return 1;
else if(n%2==0)
return -1.0/n+fun(n-1);
else
return 1.0/n+fun(n-1);
}
main()
{
int n;
scanf("%d",&n);
printf("fun(%d)=%.6f",n,fun(n));
}