Fun With Numbers

For this activity, we should ask the user for two numbers and display the following results:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

 

 

If you want to make improvements or modifications, here is the code for you to copy and paste it anywhere.

#include <iostream>
using namespace std;

double sum, diff, prod, rem;
int div;

int main (){
int a;
cout<<“Type in one number”<<endl;
cin >> a;
int b;
cout <<“Type another number”<<endl;
cin >> b;

sum=a+b;

diff=a-b;

prod=a*b;

rem=a/b;

div=a%b;

cout <<“Sum is “<< sum <<endl;

cout <<“Difference is “<< diff <<endl;

cout <<“Product is “<< prod <<endl;

cout <<“Remainder is “<< rem <<endl;

cout <<“Division is “<< div <<endl;

return 0;
}

 

Leave a comment