在C#中,可以使用System.Math
類來執行各種數學運算。下面是一些示例代碼:
double num1 = 10.5;
double num2 = 5.5;
double sum = Math.Add(num1, num2);
Console.WriteLine("The sum of " + num1 + " and " + num2 + " is " + sum);
double num = 4;
double square = Math.Pow(num, 2);
Console.WriteLine("The square of " + num + " is " + square);
double num = Math.PI;
double sine = Math.Sin(num);
Console.WriteLine("The sine of " + num + " is " + sine);
double num = Math.PI;
double cosine = Math.Cos(num);
Console.WriteLine("The cosine of " + num + " is " + cosine);
這些示例代碼演示了如何使用System.Math
類中的靜態方法執行基本的數學運算。你可以根據需要修改這些示例代碼,以適應你的具體需求。