kirililchev3

Fibonacci num

Jun 3rd, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.41 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     public static int Fibonacci(int n)
  6.     {
  7.         int a = 0;
  8.         int b = 1;
  9.  
  10.         for (int i = 0; i <= n; i++)
  11.         {
  12.             int temp = a;
  13.             a = b;
  14.             b = temp + b;
  15.         }
  16.         return a;
  17.     }
  18.  
  19.     static void Main()
  20.     {
  21.         int n = int.Parse(Console.ReadLine());
  22.  
  23.         Console.WriteLine(Fibonacci(n));
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment