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#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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:
1 2 3 4 5 | '+' operator, Result: 16 '-' operator, Result: 6 '*' operator, Result: 55 '/' operator, Result: 2 '%' operator, Result: 1 |