- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are arithmetic operators in C#?
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
Operator | Description | Example |
---|---|---|
+ | Adds two operands | A + B = 30 |
- | Subtracts second operand from the first | A - B = -10 |
* | Multiplies both operands | A * B = 200 |
/ | Divides numerator by de-numerator | B / A = 2 |
% | Modulus Operator and remainder of after an integer division | B % A = 0 |
++ | Increment operator increases integer value by one | A++ = 11 |
-- | Decrement operator decreases integer value by one | A-- = 9 |
Let us see an example to use arithmetic operators in C#.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int a = 99; int b = 33; int c; c = a + b; Console.WriteLine("Value of c is {0}", c); c = a - b; Console.WriteLine("Value of c is {0}", c); c = a * b; Console.WriteLine("Value of c is {0}", c); c = a / b; Console.WriteLine("Value of c is {0}", c); c = a % b; Console.WriteLine("Value of c is {0}", c); c = a++; Console.WriteLine("Value of c is {0}", c); c = a--; Console.WriteLine("Value of c is {0}", c); Console.ReadLine(); } } }
Output
Value of c is 132 Value of c is 66 Value of c is 3267 Value of c is 3 Value of c is 0 Value of c is 99 Value of c is 100
Advertisements