In C#, basic arithmetic operators include the following −
Home >Backend Development >C#.Net Tutorial >C# program performs all basic arithmetic operations In C#, the basic arithmetic operators include the following − To perform addition, use the addition operator− 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 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!C# program performs all basic arithmetic operations
operator
Description
< ;td style="width: 16.5253%; text-align: center;" valign="top">
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
num1 + num2;
Example
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();
}
}
}
Output
Value is 75
Value is 25
Value is 1250
Value is 2
Value is 0
Value is 50
Value is 51