Ad

Goal:
Create a program the generates the digits of Pi based on a requested digit (in base 10).

I.E.:
1 --> 3
2 --> 1
3 --> 4

If you want to use Math.PI and take the easy way out, go ahead. Just know that C# runs out of floating point precesion eventualy, so you can't just use Math.PI as you wont always get all the digits you nead. Instead, you can compute the digits yourself using an infinite series:

Pi = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 +...

using System;

public class PiDigits
{
  public static int GetDigit(int digit)
  {
    
    return (int)(Math.Floor(Math.PI*Math.Pow(10.0,(double)digit-1))-Math.Floor(Math.PI*Math.Pow(10.0,(double)digit-2))*10);
      
  }
}