C# Arithmetic Operators with Examples

In c#, Arithmetic Operators are used to perform basic arithmetic calculations like addition, subtraction, division, etc. based on our requirements.

 

For example, we have an integer variables x = 20, y = 10 and if we apply an arithmetic operator + (x + y) to perform an addition operator, then we will get the result as 30 like as shown below.

 

int result;

int x = 20, y = 10;

result = (x + y);

Following table lists the different type of operators available in c# arithmetic operators.

 

OperatorNameDescriptionExample (a = 6, b = 3)
+ Addition It adds two operands. a + b = 9
- Subtraction It subtract two operands. a - b = 3
* Multiplication It multiplies two operands. a * b = 18
/ Division It divides numerator by de-numerator. a / b = 2
% Modulo It returns a remainder as result. a % b = 0

C# Arithmetic Operators Example

Following is the example of using the Arithmetic Operators in c# programming language.

 

using System;

 

namespace Tutlane

{

    class Program

    {

        static void Main(string[] args)

        {

            int result;

            int x = 20, y = 10;

            result = (x + y);

            Console.WriteLine("Addition Operator: " + result);

            result = (x - y);

            Console.WriteLine("Subtraction Operator: " + result);

            result = (x * y);

            Console.WriteLine("Multiplication Operator: "+ result);

            result = (x / y);

            Console.WriteLine("Division Operator: " + result);

            result = (x % y);

            Console.WriteLine("Modulo Operator: " + result);

            Console.WriteLine("Press Enter Key to Exit..");

            Console.ReadLine();

        }

    }

}

If you observe above code, we used an Arithmetic operators (+, -, *, /, %) to perform different operations on defined operands based on our requirements.

Output of C# Arithmetic Operators Example 

When we execute above c# program, we will get the result like as shown below.

 

C# Arithmetic Operators Example Result 

 

This is how we can use arithmetic operators in c# programming language to perform the basic arithmetic calculations on operands based on our requirements.