Skip to content

Instantly share code, notes, and snippets.

@Ts-Pytham
Created December 22, 2020 19:27
Show Gist options
  • Save Ts-Pytham/a518e2dd70dc39b8fd7b63c91b9570cd to your computer and use it in GitHub Desktop.
Save Ts-Pytham/a518e2dd70dc39b8fd7b63c91b9570cd to your computer and use it in GitHub Desktop.
Sucesión de Fibonacci
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