Advertisement
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;
- using System.Threading.Tasks;
- namespace _22.FibonacciNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- if (n==1 || n == 0)
- {
- Console.WriteLine(1);
- return;
- }
- Console.WriteLine(Fib(n));
- }
- static int Fib(int n)
- {
- int x1 = 1;
- int x2 = 1;
- int sum = 0;
- for (int i = 2; i <= n; i++)
- {
- sum = x1 + x2;
- x1 = x2;
- x2 = sum;
- }
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement