Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Golden Ratio Approximation
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; namespace Rextester { public class Program { public static void Main(string[] args) { double error = 0.00001; //Set to desired error double goldenRatio = (1 + Math.Sqrt(5.0)) / 2; double div = 1; List<int> fib = new List<int>(); fib.Add(1); fib.Add(1); do { fib.Add(AddFibTerm(fib[fib.Count - 1], fib[fib.Count - 2])); int n2 = fib.Count - 1; int n1 = fib.Count - 2; div = (double)fib[n2]/(double)fib[n1]; } while (Math.Abs(goldenRatio - div) >= error); Console.WriteLine(fib[fib.Count - 2] + ", " + fib[fib.Count - 1] + " -> " + (double)fib[fib.Count - 1]/(double)fib[fib.Count - 2]); Console.WriteLine(); Console.WriteLine("Golden Ratio: " + goldenRatio); Console.WriteLine("Approx.: " + div); Console.WriteLine("Fib Terms: " + "F{" + (fib.Count-1) + "}: " + fib[fib.Count - 2] + ", " + "F{" + (fib.Count) + "}: " + fib[fib.Count - 1]); } //Lazy method public static int AddFibTerm(int n1, int n2) { Console.WriteLine(n2 + ", " + n1 + " -> " + (double)n1/(double)n2); return n1 + n2; } } }
run
|
edit
|
history
|
help
0
Game 1.0.4
actions and tasks
Url Encode
merge 2 sorted array
Const
knapsack
Problem_binary
Math 9.4
Simple Constructor Implementation
Found many section of times intersect (Question version)