Advertisement
ralka

[C# Basics Sample Exam May 2014] Tribonacci number

May 16th, 2016
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None
  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 _02.Simple_Loops
  9. {
  10. class SimpleLoops
  11. {
  12. static void Main(string[] args)
  13. {
  14. BigInteger first = BigInteger.Parse(Console.ReadLine());
  15. BigInteger second = BigInteger.Parse(Console.ReadLine());
  16. BigInteger third = BigInteger.Parse(Console.ReadLine());
  17. int numberOfElement = int.Parse(Console.ReadLine());
  18.  
  19. if (numberOfElement == 1)
  20. {
  21. Console.WriteLine(first);
  22. }
  23. else if (numberOfElement == 2)
  24. {
  25. Console.WriteLine(second);
  26. }
  27. else if (numberOfElement == 3)
  28. {
  29. Console.WriteLine(third);
  30. }
  31. else
  32. {
  33. for (int i = 4; i <= numberOfElement; i++)
  34. {
  35. BigInteger tribonacciNumber = first + second + third;
  36. first = second;
  37. second = third;
  38. third = tribonacciNumber;
  39. }
  40. Console.WriteLine(third);
  41. }
  42. }
  43. }
  44. }
Advertisement
RAW Paste Data Copied
Advertisement