Để tính toán giá trị lũy thừa, hãy sử dụng phương thức Math.pow ().
Ở đây, n là số và p là lũy thừa -
double res = Math.Pow(n, p);
Sau đây là mã hoàn chỉnh -
Ví dụ
using System;
class Program {
static void Main() {
double n, p;
n = 7;
p = 3;
Console.WriteLine("Exponent Power= "+n);
double res = Math.Pow(n, p);
Console.WriteLine("Result= {0}", res);
Console.ReadLine();
}
} Đầu ra
Exponent Power= 7 Result= 343