 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to perform all Basic Arithmetic Operations
Basic Arithmetic Operators in C#, include the following −
| Operator | Description | 
|---|---|
| + | Adds two operands | 
| - | Subtracts the second operand from the first | 
| * | Multiplies both operands | 
| / | Divides the numerator by de-numerator | 
| % | Modulus Operator and remainder of after an integer division | 
| ++ | Increment operator increases integer value by one | 
| -- | Decrement operator decreases integer value by one | 
To add, use the Addition Operator −
num1 + num2;
In the same way, it works for Subtraction, Multiplication, Division, and other operators.
Example
Let us see a complete example to learn how to implement Arithmetic operators in C#.
using System; namespace Sample {    class Demo {       static void Main(string[] args) {          int num1 = 50;          int num2 = 25;          int result;          result = num1 + num2;          Console.WriteLine("Value is {0}", result);          result = num1 - num2;          Console.WriteLine("Value is {0}", result);          result = num1 * num2;          Console.WriteLine("Value is {0}", result);          result = num1 / num2;          Console.WriteLine("Value is {0}", result);          result = num1 % num2;          Console.WriteLine("Value is {0}", result);          result = num1++;          Console.WriteLine("Value is {0}", result);          result = num1--;          Console.WriteLine("Value is {0}", result);          Console.ReadLine();       }    } }  Output
Value is 75 Value is 25 Value is 1250 Value is 2 Value is 0 Value is 50 Value is 51
Advertisements
 