Write Program in C++ to display the sum of two numbers. Take the two numbers as input from the user. Also show the output.
Answers
Answered by
8
Explanation:
#include <iostream>
using namespace std;
int main()
{
int firstNumber, secondNumber, sumOfTwoNumbers;
cout << "Enter two integers: ";
cin >> firstNumber >> secondNumber;
// sum of two numbers in stored in variable sumOfTwoNumbers
sumOfTwoNumbers = firstNumber + secondNumber;
// Prints sum
cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;
return 0;
}
Answered by
2
Program:
#include<iostream>
using namespace std;
int sum(int a , int b)
{
return a + b;
}
int main()
{
int a , b;
cout<<"Enter first number : ";
cin>>a;
cout<<"Enter second number : ";
cin>>b;
cout<<a<<" + "<<b<<" = "<<sum(a , b);
return 0;
}
Output:
Enter first number : 34
Enter second number : 87
34 + 87 = 121
Similar questions
India Languages,
2 months ago
English,
2 months ago
Science,
5 months ago
Math,
10 months ago
Political Science,
10 months ago