Vla_DOS

2

Apr 26th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lab2
  4. {
  5.     class Program
  6.     {
  7.         static int f1(int n)
  8.         {
  9.             int a = 1;
  10.             int b = 0;
  11.             for (int i = 1; i <= n; i++)
  12.             {
  13.                 int t = b;
  14.                 b += a;
  15.                 a = t;
  16.             }
  17.             return b;
  18.         }
  19.  
  20.         static int f2(int n)
  21.         {
  22.             if (n < 2)
  23.                 return n;
  24.             return f2(n - 1) + f2(n - 2);
  25.         }
  26.  
  27.         static void Main(string[] args)
  28.         {
  29.             Console.Write("n = ");
  30.             int n = int.Parse(Console.ReadLine());
  31.             Console.WriteLine("Result (function 1): " + f1(n));
  32.             Console.WriteLine("Result (function 2): " + f2(n));
  33.         }
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment