首先,设置前两个数字-
double val1, val2; val1 = 10; val2 = 5;
现在,使用Math.Sqrt函数来使用毕达哥拉斯定理。
res = Math.Sqrt(val1 * val1 + val2 * val2);
using System; public class Program { public static void Main(string[] args) { double val1, val2, res; val1 = 10; val2 = 5; res = Math.Sqrt(val1 * val1 + val2 * val2); Console.WriteLine("Result = {0}", res); Console.ReadLine(); } }
输出结果
Result = 11.1803398874989