「C#」Powメソッドで数値の累乗を取得するサンプル

書式
Math.Pow(数値, 指数)
MathクラスのPowメソッドを使用して、数値の累乗を取得します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
using System;
using System.IO;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
int x = 4;
int y = 2;
Console.WriteLine("累乗の計算結果: " + Math.Pow(x, y));
Console.ReadKey();
}
}
}
using System; using System.IO; namespace ConsoleApplicationSample { class Program { static void Main(string[] args) { int x = 4; int y = 2; Console.WriteLine("累乗の計算結果: " + Math.Pow(x, y)); Console.ReadKey(); } } }
using System;
using System.IO;

namespace ConsoleApplicationSample
{
    class Program
    {

        static void Main(string[] args)
        {
            int x = 4;
            int y = 2;

            Console.WriteLine("累乗の計算結果: " + Math.Pow(x, y));

            Console.ReadKey();
        }
    }
}

実行結果
累乗の計算結果: 16

C#

Posted by arkgame