Division Operator in C#

CsharpProgrammingServer Side Programming

Division operator is used in C# to divide numerator by denominator, for example 9/ 3

The division operator comes under Arithmetic Operators in C#. Let us see a complete example to learn how to implement Arithmetic operators in C#, wherein we will see how to work with division operator.

result = num1 / num2;
Console.WriteLine("Division: Value is {0}", result);

Above we have used division operator on num1 and num2.

The following is the complete example.

Example

 Live Demo

using System;
namespace Sample {
   class Demo {
      static void Main(string[] args) {
         int num1 = 50;
         int num2 = 25;
         int result;
         result = num1 + num2;
         Console.WriteLine("Value is {0}", result);
         result = num1 - num2;
         Console.WriteLine("Value is {0}", result);
         result = num1 * num2;
         Console.WriteLine("Value is {0}", result);
         result = num1 / num2;
         Console.WriteLine("Division: Value is {0}", result);
         result = num1 % num2;
         Console.WriteLine("Value is {0}", result);
         result = num1++;
         Console.WriteLine("Value is {0}", result);
         result = num1--;
         Console.WriteLine("Value is {0}", result);
         Console.ReadLine();
      }
   }
}

Output

Value is 75
Value is 25
Value is 1250
Division: Value is 2
Value is 0
Value is 50
Value is 51
raja
Published on 17-Sep-2018 08:44:40
Advertisements