Home >Backend Development >C#.Net Tutorial >Write a C# program to perform basic arithmetic calculations

Write a C# program to perform basic arithmetic calculations

PHPz
PHPzforward
2023-08-31 19:09:031272browse

编写一个 C# 程序来进行基本的算术计算

Let us do the following arithmetic calculation-

Add two operands

Sr.No th> Operators and Description
1
2 -

Subtract the second operand from the first operand

3 *

Multiply the two operands

4 /

Numerator divided by numerator

The following is Example of performing arithmetic calculations using the above operators -

Example

Live Demonstration

using System;

namespace OperatorsApplication {
   class Program {
      static void Main(string[] args) {
         int a = 40;
         int b = 20;
         int c;

         c = a + b;
         Console.WriteLine("Addition: {0}", c);

         c = a - b;
         Console.WriteLine("Subtraction: {0}", c);
     
         c = a * b;
         Console.WriteLine("Multiplication: {0}", c);

         c = a / b;
         Console.WriteLine("Division: {0}", c);

         Console.ReadLine();
      }
   }
}

Output

Addition: 60
Subtraction: 20
Multiplication: 800
Division: 2

The above is the detailed content of Write a C# program to perform basic arithmetic calculations. 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