Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    C++ Program to Add Two Given Numbers

    It is a basic C++ program that sums two given numbers. It takes two integer inputs from the user and performs arithmetic operations on them. Next, it assigns the output to a variable and then prints it on the screen.

    Example C++ Program:
    #include <iostream>
    using namespace std;
    
    int main() {
        /* Variable Declaration and Initialization. */
        int input1, input2, output;
    
        /* Taking user input */
        cout << "Please enter two integer: ";
        cin >> input1 >> input2;
        
        /* Adding the two numbers */
        output = input1 + input2;
    
        /* Prints the output to the screen */
        cout << input1 << " + " << input2 << " = " << output;
        return 0;
    }

    Program Output:

    Please enter two integer: 10
    5
    10 + 5 = 15


    Found This Page Useful? Share It!
    Get the Latest Tutorials and Updates
    Join us on Telegram

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.