Write a C++ program adds two user-specified integer values and displays the result to the screen.

Task-2: Write a C++ program adds two user-specified integer values and displays the result to the screen.

 Sample scenario:

Enter first value: 3

Enter second value: 4

Addition of 3 and 4 is 7

Try to obtain the last line as below. 3 + 4 = 7

Solution :

Input Screen

#include<iostream>

using namespace std;

int main()

{

    int a, b;

    int add;

    cout << “Enter first number” << endl;

    cin >> a;

    cout << “Enter second number” << endl;

    cin >> b;

    add = a + b;

    cout << a << ‘+’ << b << ‘=’ << add << endl;

    return 0;

}


OutPut Screen

Leave a Comment

Your email address will not be published. Required fields are marked *