什么是C#中的算术运算符?

阅读 97 收藏 0 点赞 0 评论 0

运算符是一个符号,告诉编译器执行特定的数学或逻辑操作。

运算符描述
+加两个操作数A + B = 30
--从第一个减去第二个操作数A-B = -10
*将两个操作数相乘A * B = 200
/将分子除以除分子B / A = 2
模运算符和整数除后的余数B%A = 0
++增量运算符将整数值增加一A ++ = 11
-减法运算符将整数值减一A-- = 9

让我们看一个在C#中使用算术运算符的示例。

示例

using System;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         int a = 99;
         int b = 33;
         int c;
         c = a + b;
         Console.WriteLine("Value of c is {0}", c);
         c = a - b;
         Console.WriteLine("Value of c is {0}", c);
         c = a * b;
         Console.WriteLine("Value of c is {0}", c);
         c = a / b;
         Console.WriteLine("Value of c is {0}", c);
         c = a % b;
         Console.WriteLine("Value of c is {0}", c);
         c = a++;
         Console.WriteLine("Value of c is {0}", c);
         c = a--;
         Console.WriteLine("Value of c is {0}", c);
         Console.ReadLine();
      }
   }
}

输出结果

Value of c is 132
Value of c is 66
Value of c is 3267
Value of c is 3
Value of c is 0
Value of c is 99
Value of c is 100
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号