In C#, basic arithmetic operators include the following −

Operator

In C#, basic arithmetic operators include the following −

Operator

Home  >  Article  >  Backend Development  >  C# program performs all basic arithmetic operations

C# program performs all basic arithmetic operations

WBOY
WBOYforward
2023-08-24 20:25:021241browse

C# program performs all basic arithmetic operations

In C#, the basic arithmetic operators include the following −

< ;td style="width: 16.5253%; text-align: center;" valign="top">

operator

Description

Add two operands

-

Subtract the second operand from the first operand

*

Multiply two operands

/

Divide the numerator by the denominator

%

Module Operators and remainders after integer division

The increment operator converts an integer Increase the value by one

The decrement operator reduces an integer value by one

To perform addition, use the addition operator−

num1 + num2;

Similarly, it works with subtraction, multiplication, division and other operators.

Example

Let us see a complete example to learn how to implement arithmetic operators in C#.

Real-time demonstration

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

The above is the detailed content of C# program performs all basic arithmetic operations. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Timer in C#Next article:Timer in C#