在C#中,可以使用System.Math
類來執(zhí)行各種數(shù)學運算。下面是一些示例代碼:
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
類中的靜態(tài)方法執(zhí)行基本的數(shù)學運算。你可以根據(jù)需要修改這些示例代碼,以適應你的具體需求。