1.
Write a complete program in C++ that does the following:
[4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one.
[3] displays the result of floating-point division.
Make sure to follow programming style guidelines.
Solution: Following program has been given along with the output for the requirements. Comments have been added to depict the functionality.
#include <iostream>
using namespace std;
int main()
{
//Create two integer variables
int num1,num2;
// Ask user for the first number
cout<<"Enter the First Integer : ";
cin>>num1;
// Ask user for the second number
cout<<"Enter the Second Integer : ";
cin>>num2;
//Give warning to user if second number is 0
//keep on asking the right input
while (num2 == 0)
{
cout<<"second number should be different from zero, please enter again: ";
cin>>num2;
}
//Print the different results
cout<<"Product of the two numbers: "<<num1*num2<<endl;
cout<<"Sum of the two numbers: "<<num1+num2<<endl;
cout<<"Quotient : "<<num1/num2<<endl;
cout<<"Remainder : "<<num1%num2<<endl;
cout<<"Floating Point Division : "<<static_cast<double>(num1)/static_cast<double>(num2)<<endl;
}
Output:
Enter the First Integer :
13
Enter the Second Integer : 0
second number should be different from zero, please enter again:
4
Product of the two numbers: 52
Sum of the two numbers: 17
Quotient : 3
Remainder : 1
Floating Point Division : 3.25
Get Answers For Free
Most questions answered within 1 hours.