What are arithmetic operators in C#?

CsharpProgrammingServer Side Programming

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

OperatorDescriptionExample
+Adds two operandsA + B = 30
-Subtracts second operand from the firstA - B = -10
*Multiplies both operandsA * B = 200
/Divides numerator by de-numeratorB / A = 2
%Modulus Operator and remainder of after an integer divisionB % A = 0
++Increment operator increases integer value by oneA++ = 11
--Decrement operator decreases integer value by oneA-- = 9

Let us see an example to use arithmetic operators in C#.

Example

 Live Demo

using System;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         int a = 99;
         int b = 33;
         int c;
         c = a + b;
         Console.WriteLine("Value of c is {0}", c);
         c = a - b;
         Console.WriteLine("Value of c is {0}", c);
         c = a * b;
         Console.WriteLine("Value of c is {0}", c);
         c = a / b;
         Console.WriteLine("Value of c is {0}", c);
         c = a % b;
         Console.WriteLine("Value of c is {0}", c);
         c = a++;
         Console.WriteLine("Value of c is {0}", c);
         c = a--;
         Console.WriteLine("Value of c is {0}", c);
         Console.ReadLine();
      }
   }
}

Output

Value of c is 132
Value of c is 66
Value of c is 3267
Value of c is 3
Value of c is 0
Value of c is 99
Value of c is 100
raja
Published on 18-Sep-2018 12:26:16
Advertisements