Get 2 integer inputs and display their sum.
What You'll Learn:
cin
long long
for large integers (up to 10^15)<<
operatorWhy Long Long?
The constraint (up to 10^15) exceeds the range of int
(up to ~2×10^9).
Using long long
ensures we can handle values up to approximately 9×10^18.
How cin Handles Whitespace:
The cin
operator automatically skips whitespace (spaces, tabs, newlines) when
reading numbers. This means cin >> a >> b
works whether the input is
"78 22" or "78\n22".
#include <iostream>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
cout << "Sum of " << a << " and " << b << " is " << a + b;
return 0;
}