C# Operators and Math
ExampleC#
using System;
class Program
{
static void Main()
{
int a = 17, b = 5;
Console.WriteLine(a + b);
Console.WriteLine(a / b);
Console.WriteLine(a % b);
Console.WriteLine((double)a / b > 3);
Console.WriteLine(a > b && b > 0);
int x = 10;
x += 5;
x++;
Console.WriteLine(x);
Console.WriteLine(Math.Max(3, 9));
Console.WriteLine(Math.Abs(-5));
Console.WriteLine(Math.Pow(2, 10));
}
}Output
22 3 2 True True 16 9 5 1024
As in Java and C, dividing two integers gives an integer: 17 / 5 is 3. Cast one side to double to keep decimals.
Quick check
What is 17 / 5 when both are int?
Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.
Tip: use the left and right arrow keys to move between lessons.