Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program that reads a number n and prints on the console the first n members of the Fibonacci sequence (at a single line, separated by spaces) : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, …. Note that you may need to learn how to use loops.
- using System;
- class FibonachiNums
- {
- static void Main()
- {
- Console.Write("Fibonachi numbers to display: ");
- string nums = Console.ReadLine();
- int totalNums = int.Parse(nums);
- ulong result = 0;
- ulong a = 0;
- ulong b = 1;
- Console.Write("Fibonachi sequence - ");
- for (int i = 0; i < totalNums; i++)
- {
- Console.Write(" {0}", result);
- a = result + b;
- result = b;
- b = a;
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement