← Back to C# Course | Chapter 3: Operators | Lesson 1 of 6

Arithmetic Operators

In this page:

  1. Arithmetic Operators

Arithmetic Operators

C# provides +, -, *, /, and % for basic arithmetic. Integer division truncates any fractional part, while dividing two doubles keeps precision. The % operator returns the remainder of a division.

Warning: Dividing two integers, like 7 / 2, gives 3, not 3.5 — cast one operand to double to get a fractional result.

Example: Arithmetic Operators

markup
using System;

class Program
{
    static void Main(string[] args)
    {
        int a = 7, b = 2;

        Console.WriteLine(a + b);
        Console.WriteLine(a - b);
        Console.WriteLine(a * b);
        Console.WriteLine(a / b);        // integer division
        Console.WriteLine(a % b);        // remainder
        Console.WriteLine((double)a / b); // fractional division
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.