C# Arithmetic Operators

math-symbols
In this chapter you will learn:

  • What is operator in C#?
  • What is Arithmetic Operator?
  • How to use Arithmetic operator in program?
  • What is Escape Character and how to use it?

Operators are very useful thing in computing value. While writing a program, you need various types of operators to calculate value. These operators are categorized as different categories in C sharp tutorial that performs specific task ex. The C# arithmetic operator performs basic calculation as add, subtraction, multiplication, division, and modulus whereas other operators perform different kind of task. You will learn one by one all these operators in few next chapters.

Arithmetic Operators are used for basic mathematical calculation in C# programming. The list of Arithmetic Operators is given below:

Arithmetic Operators:

OperatorDescriptionExamples
+Add numbersX=num1+num2
Subtract numbersX=num1-num2
*Multiply numbersX=num1*num2
/Divide numbersX=num1/num2
%Divide two numbers and returns reminderX=22%10 then X will be X=2

Output

Enter first number            15
Enter second number      12=====================Addition              27
Subtraction          3
Multiplication     180
Division               1.25

=======================
__

Note: \t,\n these are the special characters in C# that is known as Escape Characters. It is used for special purpose such as inserting line break, backspace etc.

 

List of Escape Characters:

Escape CharactersDescription
\’Used for single quotation mark
\”Used for double quotation mark
\\Used for backslash
\0Null
\aAudible alert
\bUsed for backspace
\fUsed for form feed
\nUsed for line break
\rUsed for Carriage return
\tUsed for horizontal tab
\vUsed for vertical tab

Summary

In this chapter, you learned about arithmetic operators in C#. You also learned how to use arithmetic operator in program. Escape characters are provides more functionality in a program so, you learned about different type escape characters in C#. In next chapter you will learn about assignment operators in C sharp.


One thought on “C# Arithmetic Operators”

Leave a Reply

Your email address will not be published. Required fields are marked *