1104 Sum of Number Segments(20 分)

找规律,emmm没找出来,看的答案

#include
#include
using namespace std;
const int maxn = 1e5 + 10;
double a[maxn];
int n;
int main()
{
    double ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lf", &a[i]);
        ans += a[i] * i*(n + 1 - i);
    }
    printf("%.2f", ans);
    return 0;
}

你可能感兴趣的:(1104 Sum of Number Segments(20 分))