很简单的一道题,可是好像存在点问题
ac不过的程序
#include <iostream>
using namespace std;
int main()
{
int N;
double num, sum = 0,result;
//cin >> N;
scanf("%d",&N);
for(int i =0; i < N; ++i){
//cin >> num;
scanf("%lf",&num);
result = (i+1) * (N-i) * num;
sum += (i+1) * (N-i) * num;
}
printf("%.2f", sum);
return 0;
}
ac过了的程序
#include<stdio.h>
int main()
{
int i,n;
double num,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%lf",&num);
sum+=num*(i+1)*(n-i);
}
printf("%.2lf",sum);
return 0;
}
更改ac不过的程序后ac过,但是不知道为啥
#include <iostream>
using namespace std;
int main()
{
int N;
double num, sum = 0,result;
//cin >> N;
scanf("%d",&N);
for(int i =0; i < N; ++i){
//cin >> num;
scanf("%lf",&num);
result = (i+1) * (N-i) * num;
sum +=(double) (i+1) * (N-i) * num;
}
printf("%.2f", sum);
return 0;
}
注意看改过后的程序和直接通过的程序的区别