Advertisement
svetoslavhl

Tribonacci_Sequence

Mar 4th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7.  
  8. double num1 = double.Parse(Console.ReadLine());
  9. double num2 = double.Parse(Console.ReadLine());
  10. double num3 = double.Parse(Console.ReadLine());
  11.  
  12. int N = int.Parse(Console.ReadLine());
  13.  
  14. if (N == 1)
  15. {
  16.  
  17. Console.WriteLine(num1);
  18. }
  19.  
  20. if (N == 2)
  21. {
  22.  
  23. Console.WriteLine(num2);
  24. }
  25.  
  26. if (N == 3)
  27. {
  28.  
  29. Console.WriteLine(num3);
  30. }
  31.  
  32. double num4 = 0;
  33.  
  34. if (N != 1 && N != 2 && N != 3)
  35. {
  36.  
  37. while (N - 3 > 0)
  38. {
  39. num4 = num1 + num2 + num3;
  40. num1 = num2;
  41. num2 = num3;
  42. num3 = num4;
  43.  
  44. N--;
  45.  
  46. }
  47.  
  48. Console.WriteLine(num4);
  49. }
  50.  
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement