Arithmetic operators help you do math with numbers in your program. They let you add, subtract, multiply, and divide values easily.
Arithmetic operators in C Sharp (C#)
result = value1 + value2; // addition result = value1 - value2; // subtraction result = value1 * value2; // multiplication result = value1 / value2; // division result = value1 % value2; // remainder (modulus)
Use + to add, - to subtract, * to multiply, / to divide, and % to get the remainder.
Division between integers gives an integer result (no decimals). Use floating-point numbers for decimal results.
int sum = 5 + 3; // sum is 8
int difference = 10 - 4; // difference is 6
int product = 7 * 6; // product is 42
int quotient = 20 / 4; // quotient is 5 int remainder = 20 % 3; // remainder is 2
This program shows how to use all the basic arithmetic operators with two numbers, 15 and 4. It prints the results for each operation.
using System; class Program { static void Main() { int a = 15; int b = 4; int sum = a + b; int difference = a - b; int product = a * b; int quotient = a / b; int remainder = a % b; Console.WriteLine($"Sum: {sum}"); Console.WriteLine($"Difference: {difference}"); Console.WriteLine($"Product: {product}"); Console.WriteLine($"Quotient: {quotient}"); Console.WriteLine($"Remainder: {remainder}"); } }
Remember that dividing two integers will cut off decimals. For example, 15 / 4 is 3, not 3.75.
Use double or float types if you want decimal results.
The modulus operator % gives the remainder after division, useful for checking if a number is even or odd.
Arithmetic operators let you do basic math in your code.
Use +, -, *, /, and % for addition, subtraction, multiplication, division, and remainder.
Integer division drops decimals; use floating-point types for precise division.