「C#」Math.Powでべき乗の計算を行うサンプル
書式
Math.Pow(数値, べき乗);
Math.Powを使用して、べき乗の計算を行います。
使用例
using System;
namespace Study
{
class Program
{
static void Main(string[] args)
{
//2の4乗を求める
double a1 = Math.Pow(2, 4);
Console.WriteLine(a1);
//-2の4乗を求める
double a2 = Math.Pow(-2,4);
Console.WriteLine(a2);
//2の0乗を求める
double a3 = Math.Pow(2, 0);
Console.WriteLine(a3);
//0の2乗を求める
double a4 = Math.Pow(0, 2);
Console.WriteLine(a4);
}
}
}
実行結果
16
16
1
0