Arithmetic Operators are used to perform mathematical operations on operands such as addition, subtraction, multiplication, division etc.
The following are the Arithmetic Operators
| operator | description |
|---|---|
+ | addition adds two operands. eg, a+b. |
- | subtraction subtracts two operands. eg, a-b. |
* | multiplication multiplies two operands. eg, a*b. |
/ | division divides the operand by the second. eg, a/b. |
% | modulo returns the remainder when the first operand is divided by the second. For example, a%b. |
Example of Arithmetic Operators in C#
using System;
namespace Operators
{
class Arithmetic
{
static void Main(string[] args)
{
int a = 11;
int b = 5;
int result;
result = a + b;
Console.WriteLine("'+' operator, Result: {0}", result);
result = a - b;
Console.WriteLine("'-' operator, Result: {0}", result);
result = a * b;
Console.WriteLine("'*' operator, Result: {0}", result);
result = a / b;
Console.WriteLine("'/' operator, Result: {0}", result);
result = a % b;
Console.WriteLine("'%' operator, Result: {0}", result);
Console.ReadLine();
}
}
}
Output:
'+' operator, Result: 16
'-' operator, Result: 6
'*' operator, Result: 55
'/' operator, Result: 2
'%' operator, Result: 1