Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Math.Pow() trong C#

Phương thức Math.Pow() trong C# tính lũy thừa: một số mũ số khác.

Cú pháp

public static double Pow(double val1, double val2)

val1 là cơ số, val2 là số mũ.

Ví dụ 1

using System;
public class Demo
{
    public static void Main()
    {
        double res;
        res = Math.Pow(5, 0);
        Console.WriteLine("Math.Pow(5,0) = " + res);
        res = Math.Pow(0, 5);
        Console.WriteLine("Math.Pow(0,5) = " + res);
    }
}

Đầu ra

Math.Pow(5,0) = 1
Math.Pow(0,5) = 0

Ví dụ 2

using System;
public class Demo
{
    public static void Main()
    {
        int val1 = 10, val2 = 15;
        float val3 = 12.8f, val4 = 25.6f;
        double res = Math.Pow(3, 2);
        Console.WriteLine("Minimum Value from two int values = " + Math.Min(val1, val2));
        Console.WriteLine("Minimum Value from two float values = " + Math.Min(val3, val4));
        Console.WriteLine("Math.Pow(3,2) = " + res);
    }
}

Đầu ra

Minimum Value from two int values = 10
Minimum Value from two float values = 12.8
Math.Pow(3,2) = 9