发布网友 发布时间:2024-10-24 04:25
共2个回答
热心网友 时间:2024-11-03 03:08
c:
#include<stdio.h>热心网友 时间:2024-11-03 03:08
#include<stdio.h>
#include<math.h>
int main(){
double fm=2.0,fz = 1.0,sum = 0,num =1 ,t = 0;
int i,n;
printf("输入一个正整数\n");
scanf("%d",&n);
for(i = 1;i<=n;i++){
if(i>1){
num = (fz/(fm));
t = fz;
fz = fm;
fm = fm+t;
if(i%2 == 0)
num = -num;
}
sum = sum + num;
}
printf("sum = %lf",sum);
return 0;
}
不谢