Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
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
Please
log in
to post a comment.
Passing Multidimensional Arrays As Arguments
extrefGenerate
vera
checkvalidtraingle
Dotnet Q-3
Prism area
Interface and it's implementation
Abstract Method Design Pattern in C#
temp1
ANQ Bug with Feb month display
stackse - search stackoverflow differently
Please log in to post a comment.