Math operators
Try it yourself →Four basic operations and remainder.
Syntax
+ - * / %
Description
The division of two integers is an integer (7/2=3). If you want a decimal, at least one must be a double (7.0/2.0=3.5). % gives the remainder.
Example
using System; Console.WriteLine(7 + 3); Console.WriteLine(7 / 2); Console.WriteLine(7.0 / 2.0); Console.WriteLine(7 % 2);
Expected output
10 3 3.5 1
When to use?
Calculations, even/odd check (number % 2).
Common mistakes
- ⚠️ Integer division truncates the decimal; use double for decimals.