📜  C#| Math.Pow()方法

📅  最后修改于: 2021-05-29 22:41:51             🧑  作者: Mango

在C#中, Math.Pow()是Math类方法。此方法用于计算将数字提高到其他数字的乘方。

句法:

public static double Pow(double base, double power)

参数:

返回类型:函数返回加到幂的底数。此方法的类型为System.Double

例子:

Input  : base = 8, power =2 
Output : 64

Input  : base = 2.5, power =3
Output : 15.625

程序:演示Math.Pow()

// C# program to illustrate the 
// Math.Pow() function
using System;
class GFG {
  
    // Main Method
    static public void Main()
    {
  
        // Find power using Math.Pow
        // 6 is base and 2 is power or
        // index or exponent of a number
        double pow_ab = Math.Pow(6, 2);
  
        // Print the result
        Console.WriteLine(pow_ab);
  
        // 3.5 is base and 3 is power or
        // index or exponent of a number
        double pow_tt = Math.Pow(3.5, 3);
  
        // Print the result
        Console.WriteLine(pow_tt);
  
        // 202 is base and 4 is power or
        // index or exponent of a number
        double pow_t = Math.Pow(202, 4);
  
        // Print the result
        Console.WriteLine(pow_t);
    }
}

输出:

36
42.875
1664966416

参考: https : //msdn.microsoft.com/zh-cn/library/system.math.pow(v=vs.110).aspx