Lesson 3.1

C# Arithmetic Operator – With Programming Examples


Objective

What is arithmetic operator in C#?
What is the symbol of Arithmetic Operator?
How to use arithmetic operator in program?

What is Arithmetic Operators?

"Arithmetic Operator is the essential part of C# operator which provides complete set of arithmetic symbol which is used for calculating numeric value. It is widely used in mathematical operation or the program which required calculation on integral value such as adding, subtracting, multiplying, dividing etc."

Arithmetic Operator Symbol

OperatorDescriptionExample
+It is used for adding two values.5 + 4 = 9
-It is used for subtract two values.5 - 4 = 1
*It is used for multiply two values.5 * 4 = 20
/It is used for dividing two values.8 / 2 = 4

Programming Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace arithmetic_operators
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1, num2, result;
            num1 = 20;
            num2 = 5;

            result = num1 + num2; //adding
            Console.WriteLine("{0} + {1} = {2}", num1, num2, result);

            result = num1 - num2; //Substract
            Console.WriteLine("{0} - {1} = {2}", num1, num2, result);

            result = num1 * num2; //Multiplying
            Console.WriteLine("{0} * {1} = {2}", num1, num2, result);

            result = num1 / num2; //dividing
            Console.WriteLine("{0} / {1} = {2}", num1, num2, result);         

            Console.ReadKey();
        }
    }
}

		 

Output

20 + 5 = 25
20 - 5 = 15
20 * 5 = 100
20 / 5 = 4
__

Summary

In this chapter you have learned what arithmetic operator, their symbol is and how to use it in your c# program. In the next chapter we will learn about Relational Operators in C#.

BackNext