# 求分数数列的前N项和

有一分数序列:2/1,-3/2,5/3,-8/5,13/8,-21/13,…, 由用户输入项目数N，求这个数列的前N 项之和

以下程序实现了这一功能，请你填补空白处内容：

```cpp
#include <stdlib.h>
#include <stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    double a1 = 2, b1 = 1;
    double a2 = 3, b2 = 2;
    double sum = a1 / b1 - a2 / b2;
    if (n == 1)
        printf("%f\n", a1 / b1);
    else if (n == 2)
        printf("%f\n", sum);
    else
    {
        for (i = 0; i < n - 2; i++)
        {
            double exp = a2 / b2;
            _____________________;
            sum += exp;
            double a = a1 + a2;
            double b = b1 + b2;
            a1 = a2;
            b1 = b2;
            a2 = a;
            b2 = b;
        }
        printf("%f\n", sum);
    }
    return 0;
}
```

## template

```cpp
#include <stdlib.h>
#include <stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    double a1 = 2, b1 = 1;
    double a2 = 3, b2 = 2;
    double sum = a1 / b1 - a2 / b2;
    if (n == 1)
        printf("%f\n", a1 / b1);
    else if (n == 2)
        printf("%f\n", sum);
    else
    {
        for (i = 0; i < n - 2; i++)
        {
            double exp = a2 / b2;
            if (i % 2 == 0)
                exp *= -1;
            sum += exp;
            double a = a1 + a2;
            double b = b1 + b2;
            a1 = a2;
            b1 = b2;
            a2 = a;
            b2 = b;
        }
        printf("%f\n", sum);
    }
    return 0;
}
```

## 答案

```cpp
if (i % 2 == 0)
    exp *= -1;
```

## 选项

### A

```cpp
if (i % 2 == 0)
    exp = -1;
```

### B

```cpp
if (i / 2 == 0)
    exp *= -1;
```

### C

```cpp
if (i / 2 == 0)
    exp = -1;
```