Advertisement
Stann

Tribonacci

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