In c#, Arithmetic Operators are useful to perform basic arithmetic calculations like addition, subtraction, division, etc., based on our requirements.
For example, we have integer variables x = 20, y = 10, and if we apply an arithmetic operator + (x + y) to perform an addition operator. We will get the result as 30 like as shown below.
The following table lists the different types of operators available in c# arithmetic operators.
Operator | Name | Description | Example (a = 6, b = 3) |
---|---|---|---|
+ | Addition | It adds two operands. | a + b = 9 |
- | Subtraction | It subtracts two operands. | a - b = 3 |
* | Multiplication | It multiplies two operands. | a * b = 18 |
/ | Division | It divides numerator by de-numerator. | a / b = 2 |
% | Modulo | It returns a remainder as a result. | a % b = 0 |
Following is the example of using the Arithmetic Operators in the c# programming language.
If you observe the above code, we used Arithmetic operators (+, -, *, /, %) to perform different operations on defined operands based on our requirements.
When we execute the above c# program, we will get the result as shown below.
This is how we can use arithmetic operators in the c# programming language to perform the basic arithmetic calculations on operands based on our requirements.