find and solve || findandsolve.com
Please wait.....

C# Arithmetic Operators

In c# programaming language, Arithmetic Operators are useful to perform basic arithmetic calculations like as Increment operator ++ · Decrement operator -- · Unary plus and minus operators · Multiplication operator *.

For example, you have integer variables firstNumber = 12, secondNumber = 8, and if you apply an arithmetic operator + (firstNumber + secondNumber) to perform an addition operator. you will get the result as 20 like as given below.

using System;  

public class TestInterface
{
    public static void Main()
    {
      int sum;
      int firstNumber = 12;
   int secondNumber = 8;
      sum = (firstNumber + secondNumber);
  Console.WriteLine("The total sum is {0}",sum);
    }

Output

The total sum is 20


The given table lists the different types of operators available in c# arithmetic operators.

OperatorNameDescriptionExample (firstNumber = 8, secondNumber = 4)
+AdditionIt adds two operands.firstNumber  + secondNumber = 12
-SubtractionIt subtracts two operands.firstNumber - secondNumber = 4
*Multiplicationmultiplies two operands.firstNumber * secondNumber = 32
/Divisiondivides numerator by de-numerator.firstNumber / secondNumber = 2
%Moduloremainder as a resultfirstNumber % secondNumber = 0


C# Arithmetic Operators Example

using System;

namespace FindAndSolve
{
   public class Program
    {
       public static void Main(string[] args)
        {
            int result;
            int firstNumber = 8, secondNumber = 4;
            result = (firstNumber + secondNumber);
            Console.WriteLine("Addition Operator: " + result);
            result = (firstNumber - secondNumber);
            Console.WriteLine("Subtraction Operator: " + result);
            result = (firstNumber * secondNumber);
            Console.WriteLine("Multiplication Operator: "+ result);
            result = (firstNumber / secondNumber);
            Console.WriteLine("Division Operator: " + result);
            result = (firstNumber % secondNumber);
            Console.WriteLine("Modulo Operator: " + result);
        }
    }
}

Output

Addition Operator: 12

Subtraction Operator: 4

Multiplication Operator: 32

Division Operator: 2

Modulo Operator: 0