Addition of two numbers in C++ Programming Language

Avatar

 BY TEJAS




C++ is the Popular Programming language in the world. After learning C programming language everybody learn C++ language. C++ is object oriented language such like as java. In IT field their is demand for C++ programmers.

For Addition of Two Numbers in C++ you have to assign num1, num2, and sum in int but also you can assume it in float, As your wish. Then we print the value using cout which is pre-defined function in C++. Then we call cin function for getting values from keyboard (user). Then we write the formula
sum = num1 + num2
Then we return call the function cout to print the answer which is we got.
That's It.




It is a very simple example which is a basic example while learning C++ language.

Addition of 2 Numbers


In java, C, and Python there is also a same example.


In below video shows program


below here is a C++ code program and output of C++ program.


Note:-

In C++ language there is some different names of functions from C language.


Extension of C++ Program is .cpp


main.cpp :-
    

        #include <iostream>
            using namespace std;
            int main()
            {
                int num1, num2, sum;
        
                cout << "Enter First Number: ";
                cin >> num1;
                cout << "Enter First Number: ";
                cin >> num2;
                // sum of two numbers in stored in variable sumOfTwoNumbers
                sum = num1 + num2;
                // Prints sum
                cout << "Addition of " << num1 << " and " <<  num2 << " is " << sum;
                return 0;
            }
        

    


output :-
    
        Enter First Number: 5
        Enter First Number: 9
        Addition of 5 and 9 is 14

    
  
    
        #include <iostream>
            using namespace std;
            int main()
            {
                int num1, num2, sum;
        
                cout << "Enter First Number: ";
                cin >> num1;
                cout << "Enter First Number: ";
                cin >> num2;
                // sum of two numbers in stored in variable sumOfTwoNumbers
                sum = num1 + num2;
                // Prints sum
                cout << "Addition of " << num1 << " and " <<  num2 << " is " << sum;
                return 0;
            }
        
    


output :-
    
     
        Enter First Number: 5
        Enter First Number: 9
        Addition of 5 and 9 is 14

    
  
Search
Advertisement
Share With
Follow us on
Advertisement