編寫一個 C# 程式,進行基本算術運算


以下為使用上述運算子執行算術運算的示例 −

序號運算子和描述
1+
對兩個運算元進行加法
2-
從第一個運算元中減去第二個運算元
3*
對兩個運算元進行乘法
4/
將分子除以分母

以下示例使用上述運算子執行算術運算 −

示例

 線上演示

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

輸出

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

更新於: 22-6-2020

505 次檢視

開啟你的職業生涯

完成課程獲取證書

開始學習
廣告
© . All rights reserved.