Home > Backend Development > C#.Net Tutorial > C# program performs all basic arithmetic operations

C# program performs all basic arithmetic operations

WBOY
Release: 2023-08-24 20:25:02
forward
1307 people have browsed it

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;
Copy after login

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();
      }
   }
}
Copy after login

Output

Value is 75
Value is 25
Value is 1250
Value is 2
Value is 0
Value is 50
Value is 51
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template