本帖最後由 李泳霖 於 2024-1-9 17:04 編輯
- //數字常見用法
- int a = 5, b = 2;
- System.Console.WriteLine("a + b = " + (a + b));
- System.Console.WriteLine("a - b = " + (a - b));
- System.Console.WriteLine("a * b = " + (a * b));
- System.Console.WriteLine("a / b = " + (a / b));
- System.Console.WriteLine("a % b = " + (a % b));
- System.Console.WriteLine(5 / 2);
- System.Console.WriteLine(5 / 2.0);
- System.Console.WriteLine(5.0 / 2);
- System.Console.WriteLine(5+2*3);
- //常用數學方法
- System.Console.WriteLine("--------------------\n"+System.Math.Abs(-10));//絕對值
- System.Console.WriteLine(System.Math.Pow(2,3));//次方
- System.Console.WriteLine(System.Math.Sqrt(64));//根號
- System.Console.WriteLine(System.Math.Max(2, 100));//最大值
- System.Console.WriteLine(System.Math.Min(2, 100));//最小值
- System.Console.WriteLine(System.Math.Round(3.5));//四捨五入
複製代碼 |