https://projecteuler.net/problem=13
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
I try to solve it using C++ in Xcode. I saved the numbers in a file and built it successfully but got the wrong answer. Here is my code:
#include <fstream>
#include <iostream>
using namespace std;
int main(void) {
double sum = 1;
double num;
ifstream fin("/Users/pwd/programs/projectEuler13/num.txt");
while (fin) {
fin >> num;
sum += num;
}
fin.close();
cout.precision(12);
cout << sum << endl;
return 0;
}
I got the result: 5.59087976462e+51
So first 10 digits of the sum: 5590879764. But it is wrong. What is wrong with my code?