Skip to main content

Posts

Showing posts with the label difference and product. Print each of the results in separate lines.

Write a C++ program that ask user to enter two numbers, calculate and display their sum, difference and product. Print each of the results in separate lines.

 here's a C++ program that asks the user to enter two numbers, calculates their sum, difference, and product, and then prints each of the results in separate lines: #include <iostream> using namespace std; int main() {     // Declare variables to store the two numbers     int num1, num2;     // Prompt the user to enter the first number     cout << "Enter the first number: ";     cin >> num1;     // Prompt the user to enter the second number     cout << "Enter the second number: ";     cin >> num2;     // Calculate the sum, difference, and product     int sum = num1 + num2;     int diff = num1 - num2;     int prod = num1 * num2;     // Print each result in a separate line     cout << "Sum: " << sum << endl;     cout << "Difference: " << diff << endl;     cout ...