標題:
[3-2]基本計算機
[打印本頁]
作者:
李泳霖
時間:
2023-11-13 12:06
標題:
[3-2]基本計算機
//基本計算機
//System.Convert.ToInt32轉整數
int num1, num2;
System.Console.Write("請輸入第一個數:");
num1 = System.Convert.ToInt32(System.Console.ReadLine());
System.Console.Write("請輸入第二個數:");
//若為浮點數會出錯
num2 = System.Convert.ToInt32(System.Console.ReadLine());
System.Console.WriteLine(num1+" + "+num2+" = "+(num1+num2));
複製代碼
//基本計算機
//System.Convert.ToInt32轉整數
double num1, num2;
System.Console.Write("請輸入第一個數:");
num1 = System.Convert.ToDouble(System.Console.ReadLine());
System.Console.Write("請輸入第二個數:");
num2 = System.Convert.ToDouble(System.Console.ReadLine());
System.Console.WriteLine(num1 + " + " + num2 + " = " + (num1 + num2));
System.Console.WriteLine(num1 + " - " + num2 + " = " + Math.Round(num1 - num2,2));
System.Console.WriteLine(num1 + " * " + num2 + " = " + (num1 * num2));
System.Console.WriteLine(num1 + " / " + num2 + " = " + Math.Round(num1 / num2,2));
System.Console.WriteLine(num1 + " % " + num2 + " = " + Math.Round(num1 % num2),2);
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2