Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- class StackFibonacci
- {
- static void Main()
- {
- Stack<long> fibonacii = new Stack<long>();
- int n = int.Parse(Console.ReadLine());
- fibonacii.Push(1);
- fibonacii.Push(1);
- for (int i = 0; i < n - 2; i++)
- {
- long a = fibonacii.Pop();
- long b = fibonacii.Peek();
- fibonacii.Push(a);
- fibonacii.Push(a + b);
- }
- Console.WriteLine(fibonacii.Peek());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment