Arithmetic Operators in C#
Notes:
Arithmetic Operators in C# Programming Language:
- C# provides 5 arithmetic operators to perform arithmetic operations. They are
+: Addition Operator : sum of two numbers
- : Subtraction Operator : difference between two numbers
*: Multiplication Operator : product of two numbers
/: Division Operator : quotient of a complete division operation
%: Modulus Operator : remainder of a first division operation
Example Code:
using System;
namespace ArithmeticOperatorsDemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(2 + 2); // 4
Console.WriteLine(5 + 2); // 7
Console.WriteLine(5 - 2); // 3
Console.WriteLine(10 - 2); // 8
Console.WriteLine(5 * 2); // 10
Console.WriteLine(10 * 2); // 20
Console.WriteLine(10 / 2); // 5
Console.WriteLine(10 % 2); // 0
Console.WriteLine(11 / (float) 2); // 5.5
Console.WriteLine(11 % 2); // 1
// Console.WriteLine(10 / 0); // division by zero error
Console.ReadKey();
}
}
}