Cpp - Binary arithmetic operators

Introduction

Arithmetic operators are used to perform calculations.

Operator Significance
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder

Demo

#include <iostream> 
using namespace std; 
int main() /* ww w . j  a va 2s.  c om*/
{ 
  double x, y; 
  cout << "\nEnter two floating-point values: "; 
  cin >> x >> y; 
  cout << "The average of the two numbers is: " 
       << (x + y)/2.0 << endl; 
  return 0; 
}

Result

Note

Divisions performed with integral operands will produce integral results; for example, 7/2 equals to 3.

If at least one of the operands is a floating-point number, the result will be a floating-point number; e.g., the division 7.0/2 produces 3.5.

Remainder division is only applicable to integral operands and returns the remainder of an integral division. For example, 7%2 returns 1.

Related Topic