#include<stdio.h>
int main(){
int a=1,b=1,n,i;
int arr[]={1};
float s=arr[0];
scanf("%d",&n);
for(i=1;i<n;i++){
b+=1;
arr[i]=a/b;
if(i%2!=0) arr[i]=-arr[i];
else arr[i]=arr[i];
s+=arr[i];
}
printf("%.2f",s);
return 0;
}
原文地址:https://www.cnblogs.com/huoyuying/p/9735687.html
时间: 2024-11-06 09:51:22