// ---
// jupyter:
//   jupytext:
//     text_representation:
//       extension: .cs
//       format_name: light
//       format_version: '1.5'
//       jupytext_version: 1.14.4
//   kernelspec:
//     display_name: .NET (C#)
//     language: C#
//     name: .net-csharp
// ---

// + dotnet_interactive={"language": "csharp"}
bool check(double prev, double pi ,  int n){
   if((uint)(Math.Pow(10,n)*prev)==(uint)(Math.Pow(10,n)*pi)) return true;
   return false;
}

double step(int stp){
   double s=2*stp;
   if(stp%2==0)
      return (double)(-4/(s*(s+1)*(s+2)));
   return (double)(4/(s*(s+1)*(s+2)));
   
}
step(2)

// + dotnet_interactive={"language": "csharp"}
double pi(int n){
   double prev=0;
   double pi=3;
   int stp=0;

   while(!check(prev,pi,n)){
      stp++;
      prev=pi;
      pi+=step(stp);
   }

   return (double)((long)(Math.Pow(10,n)*pi)/Math.Pow(10,n));
}

pi(7)

StarcoderdataJupyterScriptsDedupFiltered