codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ how to: add two numbers

C++ how to: add two numbers

Read two numbers and add.

Read with cin and print the sum.

Example code

#include <iostream>
using namespace std;
int main() {
  int a, b;
  cout << "Two numbers: ";
  cin >> a >> b;
  cout << "Sum = " << a + b << endl;
  return 0;
}

Run this code in the online editor

← C++ namespacesC++ how to: random numbers →