a1104专题

PAT A1104 Sum of Number Segments 中的隐式转换问题

题目本身不难,我一开始写的代码是 #include<stdio.h>int main(){int N;scanf("%d", &N);double ans = 0.0;for(int i=0; i<N; i++){double cur;scanf("%lf", &cur);ans += (i+1) * (N-i) * cur;}printf("%.2lf", ans);return 0;}