Created
December 22, 2020 19:27
-
-
Save Ts-Pytham/a518e2dd70dc39b8fd7b63c91b9570cd to your computer and use it in GitHub Desktop.
Sucesión de Fibonacci
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
using System; | |
using System.Numerics; | |
namespace Serie_de_Fibonacci | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Ingrese la posición para hallar el número de la sucesión de Fibonacci: "); | |
int pos = int.Parse(Console.ReadLine()); | |
Console.WriteLine($"El valor es: {Fibonacci(pos)}"); | |
} | |
static BigInteger Fibonacci(int pos) | |
{ | |
if (pos < 0) | |
throw new ArgumentOutOfRangeException(); | |
else if (pos == 0) | |
return 0; | |
else if (pos == 1 || pos == 2) | |
return 1; | |
else | |
return (BigInteger)(-(Math.Sqrt(5) / 5) * Math.Pow((1 - Math.Sqrt(5)) / 2, pos) + (Math.Sqrt(5) / 5) * Math.Pow((1 + Math.Sqrt(5)) / 2, pos)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment