Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //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.
- class Program
- {
- static void Main()
- {
- int lengthFi = int.Parse(Console.ReadLine());
- int tempA = 0;
- int tempB = 1;
- for (int i = 0; i < lengthFi; i++)
- {
- Console.Write(tempA + " ");
- int temp = tempA;
- tempA = tempB;
- tempB = temp + tempB;
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement