Home Basics C# Arithmetic operators

C# Arithmetic operators

Arithmetic operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, etc.

The following table shows these opearators

Operator Operator Name Example
+ Addition Operator 6 + 4 evaluates to 10
Subtraction Operator 10 – 5 evaluates to 5
* Multiplication Operator 5 * 2 evaluates to 10
/ Division Operator 10 / 5 evaluates to 2
% Modulo Operator (Remainder) 16 % 3 evaluates to 1

Example

Lets see an example of this in action

 

using System;

public class Program
{
	public static void Main()
	{
		int result;
		int x = 40, y = 20;
		result = (x + y);
		Console.WriteLine("Addition Operator example: " + result);
		result = (x - y);
		Console.WriteLine("Subtraction Operator example: " + result);
		result = (x * y);
		Console.WriteLine("Multiplication Operator example: " + result);
		result = (x / y);
		Console.WriteLine("Division Operator example: " + result);
		result = (x % y);
		Console.WriteLine("Modulo Operator example: " + result);
		Console.WriteLine("Press Enter Key to Exit..");
		Console.ReadLine();
	}
}

You should see the following

Addition Operator example: 60
Subtraction Operator example: 20
Multiplication Operator example: 800
Division Operator example: 2
Modulo Operator example: 0
Press Enter Key to Exit..

You may also like