gfgdf
#include <iostream>
int main() {
int num1, num2, sum;
// Input
std::cout << "Enter two numbers: ";
std::cin >> num1 >> num2;
// Addition
sum = num1 + num2;
// Output
std::cout << "Sum: " << sum;
return 0;
}
Explanation:
#include <iostream>
: This line includes the input/output stream library in the program.int main() {
: This line declares the main function, the starting point of execution for C++ programs.int num1, num2, sum;
: Declares three integer variablesnum1
,num2
, andsum
to store input numbers and their sum.std::cout << "Enter two numbers: ";
: Displays the prompt to enter two numbers on the console.std::cin >> num1 >> num2;
: Takes input from the user fornum1
andnum2
.sum = num1 + num2;
: Calculates the sum ofnum1
andnum2
and assigns it to the variablesum
.std::cout << "Sum: " << sum;
: Displays the result (sum) on the console.return 0;
: Indicates successful program execution and returns 0 to the operating system.}
: Marks the end of themain
function and the end of the program.