如何使用 C# 计算幂指数值?
使用 Math.pow() 方法计算幂指数值。
其中,n 是数字,p 是幂 −
double res = Math.Pow(n, p);
以下是完整代码 −
示例
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();
}
}输出
Exponent Power= 7 Result= 343
广告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP