-2147483648
如果我输入两个足够大的数字,整数会限制我的答案。我可以替换double v1 = 0, v2 = 0
为我的代码吗?如果我这样做,有没有办法让它输出答案的全长(不是5e+17
等)
谢谢。
#include <iostream>
using namespace std;
int main ()
{
cout << "Enter two numbers: " << endl;
int v1 = 0, v2 = 0;
cin >> v1 >> v2;
int sum = 0, val = v1;
while (val <= v2)
{
sum += val;
++ val;
}
cout << "The sum of " << v1 << " through " << v2 << " inclusive is " << sum << endl;
return 0;
}