using System;
using System.Collections.Generic;
using System.Text;       
        /*
         * 利用循环迭代法求PI
         * ∏/4=1-1/3+1/5-1/7+1/9…公式求∏的近似值,
         * 直到最后一项的绝对值小于 10的-6次方为止。
         */
class Program
    {
        static void Main(string[] args)
        {
                Console.WriteLine(GetPI());
        }
   static double GetPI()
        {
            double pi = 0;
            double k = 0;
            double i = 1;
            int n = 1;
            do
            {
                k = n / i;
                pi += k;
                i += 2;
                n = -n;
            } while (Math.Abs(k)>=1e-8);
            return 4*pi;
        }

   }