Basic Math Operators in C++

Download
Download is available until [expire_date]
  • Version
  • Download 22
  • File Size 1.41 KB
  • File Count 1
  • Create Date April 18, 2016
  • Last Updated April 18, 2016

Basic Math Operators in C++

Basic Math Operators in C++

This is an example program in c++ that demonstrate the four basic mathematical operators in action (add, subtract, divide, multiply). The program will ask the user to input two numbers, then the program will display the result of the four basic math operations.

Source code:

#include < iostream >

using namespace std;

int main()
{
    double firstnum, secondnum, sum, quotient, difference, product;

    cout << "enter first number" << endl;
    cin>>firstnum;
    cout << "enter second number" << endl;
    cin>>secondnum;

    sum=firstnum+secondnum;
    quotient=firstnum/secondnum;
    difference=firstnum-secondnum;
    product=firstnum*secondnum;

    cout << "the sum of " << firstnum  << " and " << secondnum <<" = " << sum << endl;
    cout << "the quotient of " << firstnum  << " and " << secondnum <<" = " << quotient << endl;
    cout << "the difference of " << firstnum << " and " << secondnum <<" = " << difference << endl;
    cout << "the product of " << firstnum << " and " << secondnum <<" = " << product << endl;
    return 0;
}
, , , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.