算術運算符+ - * / % ++ -- 舉例:1. while (true) { Console.Write("請輸入整數a:"); int a = int.Parse(Console.ReadLine()); Console.Write("請輸入整數b:"); int b = int.Parse ...
算術運算符+ - * / % ++ --
舉例:1.
while (true)
{
Console.Write("請輸入整數a:");
int a = int.Parse(Console.ReadLine());
Console.Write("請輸入整數b:");
int b = int.Parse(Console.ReadLine());
int c = a + b;
Console.Write("加法結果是:" + c);
c = a - b;
Console.Write("減法結果是:" + c);
c = a * b;
Console.Write("乘法結果是:" + c);
c = a / b;
Console.Write("除法結果是:" + c);
c = a % b;
Console.Write("取餘數結果是:" + c);
}
2.
Console.Write("請輸入整數a:");
int a = int.Parse(Console.ReadLine());
Console.Write("請輸入整數b:");
int b = int.Parse(Console.ReadLine());
int c =a++;// int c=a;a=a+1;
int d =++a;//a=a+1;int d=a;
Console.WriteLine(c);
Console.WriteLine(d);
比較運算符> < >= <= != ==
Console.Write("請輸入整數a:");
int a = int.Parse(Console.ReadLine());
Console.Write("請輸入整數b:");
int b = int.Parse(Console.ReadLine());
bool c = a > b;
Console.WriteLine(c);
Console.ReadLine();
邏輯運算符&& || !
Console.Write("請輸入整數a:");
int a = int.Parse(Console.ReadLine());
Console.Write("請輸入整數b:");
int b = int.Parse(Console.ReadLine());
c=15;
bool L= a > b||a>c&&b>c;
Console.WriteLine(L);
Console.ReadLine();
條件運算符 ?:
賦值運算符 = += -= *= /= %=
優先順序:
前++ ——
* / %
+-
> < >= <= == !=
&& || !