Venciity

[SoftUni C# exam preparation] 02.Tribonacci

Apr 10th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. class Tribonacci
  9. {
  10.     static void Main(string[] args)
  11.     {
  12.         BigInteger t1 = long.Parse(Console.ReadLine());
  13.         BigInteger t2 = long.Parse(Console.ReadLine());
  14.         BigInteger t3 = long.Parse(Console.ReadLine());
  15.         int n = Int32.Parse(Console.ReadLine());
  16.  
  17.         if (n == 1)
  18.         {
  19.             Console.WriteLine(t1);
  20.         }
  21.         else if (n == 2)
  22.         {
  23.             Console.WriteLine(t2);
  24.         }
  25.         else if (n == 3)
  26.         {
  27.             Console.WriteLine(t3);
  28.         }
  29.         else
  30.         {
  31.             BigInteger tn = 0;
  32.             for (int i = 4; i <= n; i++)
  33.             {
  34.                 tn = t1 + t2 + t3;
  35.                 t1 = t2;
  36.                 t2 = t3;
  37.                 t3 = tn;
  38.             }
  39.             Console.WriteLine(tn);
  40.         }
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment