「C#」Math.PIで円周率を使用する方法
構文
数値 算術演算子 Math.PI;
MathクラスのPIフィールドを使用して、円周率を使用した計算を行います。
PIフィールドには、円周率(3.14159265358979)が設定されます。
使用例
using System;
using System.IO;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
//半径
int xx = 4;
//円の面積の計算
double result = Math.Pow(xx, 2) * Math.PI;
Console.WriteLine("円の面積: " + result);
Console.ReadKey();
}
}
}
using System;
using System.IO;
namespace ConsoleApplicationSample
{
class Program
{
static void Main(string[] args)
{
//半径
int xx = 4;
//円の面積の計算
double result = Math.Pow(xx, 2) * Math.PI;
Console.WriteLine("円の面積: " + result);
Console.ReadKey();
}
}
}
using System; using System.IO; namespace ConsoleApplicationSample { class Program { static void Main(string[] args) { //半径 int xx = 4; //円の面積の計算 double result = Math.Pow(xx, 2) * Math.PI; Console.WriteLine("円の面積: " + result); Console.ReadKey(); } } }
実行結果
円の面積: 50.2654824574367