Write a program in C++ to print the sum of two numbers using variables

0 0
Read Time:39 Second

Here’s a simple C++ program to achieve that:

#include <iostream>
using namespace std;

int main() {
    int num1 = 29;
    int num2 = 30;
    int sum = num1 + num2;

    cout << "Print the sum of two numbers:" << std::endl;
    cout << "-----------------------------" << std::endl;
    cout << "The sum of " << num1 << " and " << num2 << " is: " << sum << std::endl;

    return 0;
}

Output:

Print the sum of two numbers :
———————————–
The sum of 29 and 30 is : 59

This program declares two integer variables num1 and num2 and initializes them with the values 29 and 30 respectively. Then it calculates their sum and stores it in another variable sum. Finally, it prints out the sum along with the numbers.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %