The input holds whole numbers, but you are not told how many. Read them all and print how many there were and their sum.
Input
Up to 10,000 whole numbers (each from -10⁹ to 10⁹), separated by spaces and newlines.
Output
COUNT SUM
Examples
Example 1 · Input
5 8 -2 10 4
Expected output
5 25
Example 2 · Input
7
Expected output
1 7
Hints
Hint 1
while (cin >> x) keeps reading until there are no more numbers.
Hint 2
Use long long for the sum.
Solution
Show one correct solution (try it yourself first)
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long x, sum = 0;
int count = 0;
while (cin >> x) {
sum += x;
count++;
}
cout << count << " " << sum << "\n";
return 0;
}