What is Arithmetic Operators With Example Code

In C#, arithmetic operators are used to perform arithmetic operations such as addition, subtraction, multiplication, division, and modulus. Here's a program demonstrating arithmetic operators







using System;
 
class Program
{
    static void Main(string[] args)
    {
        // Addition (+): Adds two numbers together.
        int a = 10;
        int b = 5;
        int additionResult = a + b;
        Console.WriteLine($"Addition Result: {a} + {b} = {additionResult}");
 
        // Subtraction (-): Subtracts the second number from the first.
        int subtractionResult = a - b;
        Console.WriteLine($"Subtraction Result: {a} - {b} = {subtractionResult}");
 
        // Multiplication (*): Multiplies two numbers together.
        int multiplicationResult = a * b;
        Console.WriteLine($"Multiplication Result: {a} * {b} = {multiplicationResult}");
 
        // Division (/): Divides the first number by the second.
        int divisionResult = a / b;
        Console.WriteLine($"Division Result: {a} / {b} = {divisionResult}");
 
        // Modulus (%): Computes the remainder when the first number is divided by the second.
        int modulusResult = a % b;
        Console.WriteLine($"Modulus Result: {a} % {b} = {modulusResult}");
    }
}


 

//a and b are integer variables initialized with values.
//Addition (+): Adds the values of a and b.
//Subtraction (-): Subtracts the value of b from a.
//Multiplication (*): Multiplies the values of a and b.
//Division (/): Divides the value of a by b.
//Modulus (%): Computes the remainder of dividing a by b.

//Result
//Addition Result: 10 + 5 = 15
//Subtraction Result: 10 - 5 = 5
//Multiplication Result: 10 * 5 = 50
//Division Result: 10 / 5 = 2
//Modulus Result: 10 % 5 = 0