Arithmetic Operators
The given table below lists the arithmetic operators provided in C++. They can be applied to some built in data_type allowed via C++ language. The unary minus, in effect multiplies its single operand by -1. Thus, a number preceded through a minus sign changes its sign.
The modulus division (%) operation yields the remainder of an integer division. Therefore, % cannot be used on type float or double.
The given code fragment describes the use: -
# include <iostream.h>
void main()
{
int x, y;
x=10; y=3;
cout<<x / y; /* displays 3, division of two integers*/
cout<<x % y); /* displays 1, the remainder of the integer division */
x=1; y=2;
cout<<x / y); /* displays 0, integer division 1/2 yeilds 0 */
cout<< x % y; /* displays 1, the remainder of integer division */
}
The output is:
3 10 1