1104 Sum of Number Segments (20分) (long double) C++

long double类型的数,输入时要写Lf,见识到了,成功从17分到AC!

#include<bits/stdc++.h>
using namespace std;
long double sum,num;	//关键所在
int n;
int main()
{
    
    
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
    
    
		scanf("%Lf",&num);
		sum+=num*(n-i+1)*i;
	}
	printf("%.2Lf",sum);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Jay_fearless/article/details/109392632