0

How the logic works?

public static void Main() { int n; int a = 0; int b = 1; Console.Write("Enter the limit : "); n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { Console.WriteLine(a); int temp = a; a = b; b = temp + b; } Console.Read();

7th Apr 2018, 5:53 AM
Jeya Prakash J
Jeya Prakash J - avatar
2 Respostas
+ 4
n - no. of values to print. temp - temporary variable for the purpose of swapping a and b. In fibonacci series the next umber is determined by adding the number at current position and previous position. Here, we print a number and swap it to a temporary variable then get the next number from b to a, then we get the next to next number on b by adding the current and last number.
9th Apr 2018, 5:45 AM
Rusty.Metal
0
マυѕту thanks bro
9th Apr 2018, 8:26 AM
Jeya Prakash J
Jeya Prakash J - avatar