Created
March 31, 2015 18:08
-
-
Save gavilanch/cb2c3248f326c773d80f to your computer and use it in GitHub Desktop.
Nth decimal of Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
///This function returns the nth decimal of Pi | |
/// </summary> | |
/// <param name="lugar"></param> | |
/// <returns></returns> | |
private int ObtenerDecimalNdePi(int lugar) | |
{ | |
double Pi = Math.PI; | |
double Potencia = Math.Pow(10, lugar); | |
double PotenciaFloor = Math.Pow(10, lugar-1); | |
double PiPorPotenciaFloor = Math.Floor(Pi * PotenciaFloor) * 10; | |
double resultado = Pi * Potencia - PiPorPotenciaFloor; | |
return (int)Math.Floor(resultado); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment