In C#, the basic arithmetic operators include the following −
operator | Description |
---|---|
Add two operands | |
- | Subtract the second operand from the first operand |
* | Multiply two operands |
/ | Divide the numerator by the denominator |
% | Module Operators and remainders after integer division |
The increment operator converts an integer Increase the value by one | |
The decrement operator reduces an integer value by one |
To perform addition, use the addition operator−
num1 + num2;
Similarly, it works with subtraction, multiplication, division and other operators.
Let us see a complete example to learn how to implement arithmetic operators in C#.
Real-time demonstration
using System; namespace Sample { class Demo { static void Main(string[] args) { int num1 = 50; int num2 = 25; int result; result = num1 + num2; Console.WriteLine("Value is {0}", result); result = num1 - num2; Console.WriteLine("Value is {0}", result); result = num1 * num2; Console.WriteLine("Value is {0}", result); result = num1 / num2; Console.WriteLine("Value is {0}", result); result = num1 % num2; Console.WriteLine("Value is {0}", result); result = num1++; Console.WriteLine("Value is {0}", result); result = num1--; Console.WriteLine("Value is {0}", result); Console.ReadLine(); } } }
Value is 75 Value is 25 Value is 1250 Value is 2 Value is 0 Value is 50 Value is 51
The above is the detailed content of C# program performs all basic arithmetic operations. For more information, please follow other related articles on the PHP Chinese website!