Arithmetic operators in C#

(Last Updated On: January 29, 2019)

Learn about arithmetic operators in C# programming i.e. + plus, – minus, * multiplication, /division and % modulo operators with simple example and explanation.

Below are the arithmetic operators in C# language that are used to perform arithmetic operations on primitive data types i.e. int, float and double etc in C#.

  • + Plus
  • – Minus/Subtraction
  • * Multiplication
  • / Division
  • % Modulus or remainder operator

 

NOTE:

About Modulus Operator, some of the people may not be understanding % modulus operator. So, here is brief about % MODULUS OPERATOR.

The % operator returns the remainder of two numbers. For example, 10 % 4 is 2 because 10 divided by 4 leaves a remainder of 2.

Another example,

5%2 leaves a remainder of 1.

 

Code Example on arithmetic operators in C#

In below C# program, two numbers are given 20 and 30 in variables a and b respectively. The program has demonstrated how to perform arithmetic operations
using on two numbers using each arithmetic operators’ and output.

Output

 

More on Arithmetic operators in C#

Arithmetic operators follow the BODMOS Rule that we have already studied in school. That is perform div, then multiplication, then + or – etc.

C# language follows the same.

For example, expression 2+2/2*2 will result into 4.

C# code:

Output:
result =4.0