Friday 17 August 2018

C#: Arithmetic Operators

Arithmetic operators are used to perform arithmetic operation on operands.

Operator
Description
+
Addition (also used for String concatenation)
-
Subtraction
/
Division
*
Multiplication
%
Remainder
++
Pre or post increment
--
Pre or post decrement



Program.cs
using System;

class Program
{
    static void Main(string[] args)
    {
        int operand1 = 30;
        int operand2 = 10;

        Console.WriteLine("operand1 = {0}", operand1);
        Console.WriteLine("operand2 = {0}", operand2);
        Console.WriteLine("Addition of operand1 and operand2 is {0}", (operand1 + operand2));
        Console.WriteLine("Subtraction of operand1 and operand2 is {0}", (operand1 - operand2));
        Console.WriteLine("Multiplication of operand1 and operand2 is {0}", (operand1 * operand2));
        Console.WriteLine("Division of operand1 and operand2 is {0}", (operand1 / operand2));
        Console.WriteLine("Remainder of operand1 and operand2 is {0}", (operand1 % operand2));
    }
}


Output
operand1 = 30
operand2 = 10
Addition of operand1 and operand2 is 40
Subtraction of operand1 and operand2 is 20
Multiplication of operand1 and operand2 is 300
Division of operand1 and operand2 is 3
Remainder of operand1 and operand2 is 0





Previous                                                 Next                                                 Home

No comments:

Post a Comment