2015-11-17 01:42

Description

Input

Output

Sample Input
1
2
3

Sample Output
2.0000000000
3.5000000000

# 5.1666666667

#include
int main(void){
double i, n, j, x, sum, tem, x1, x2, y1, y2, y;
while(scanf("%lf", &n)!=EOF&&n>=0){
x1=2; x2=3; y1=1; y2=2; sum=0;

if(n==0) sum=-3.5;
else if(n==1) sum=-1.5;
else if(n==2) sum=0;
else
for(i=1; i<=n-2; i++){
x=x1+x2; x2=x1; x1=x; y=y1+y2; y2=y1; y1=y;
sum=sum+x/y;
}

printf("%.10f\n", sum+3.5);
}
return 0;
}

• 写回答
• 好问题 提建议
• 追加酬金
• 关注问题
• 收藏
• 邀请回答

#### 5条回答默认 最新

• yangbo50304 2015-11-17 03:04
已采纳

不知道你写的为啥不对，我写了一个，c语言的

`````` struct Node
{
double number;
Node* pNext;
Node()
{
number = 0;
pNext = NULL;
}
};
int main()
{
int n = -1;
Node* pNode = new Node;
Node* pPre = pNode;
while (scanf_s("%d", &n) != EOF)
{
pNode->number = n;
Node* pNext = new Node;
pNode->pNext = pNext;
pPre = pNode;
pNode = pNext;
}

delete pNode;
pPre->pNext = NULL;
double sum = 0.0;
while (pNode->pNext != NULL)
{
double d = pNode->pNext->number / pNode->number;
sum += d;
printf("%.10f\n", sum);
pNode = pNode->pNext;
}

return 0;
}
``````
评论
解决 无用
打赏 举报
• 查看更多回答(4条)