Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace P5CalculateSequenceWithQueue
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- Console.WriteLine(getFibonacci(n));
- }
- private static long getFibonacci(int n)
- {
- Stack<long> numbers = new Stack<long>();
- long a = 0;
- long b = 1;
- numbers.Push(a);
- numbers.Push(b);
- for (int i = 1; i < n; i++)
- {
- long c = a;
- a = numbers.Peek();
- numbers.Push(c + b);
- b = numbers.Peek();
- }
- return numbers.Peek();
- }
- }
- }
Add Comment
Please, Sign In to add comment