Advertisement
Guest User

02. Simple Loops

a guest
Mar 20th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. BigInteger a1 = new BigInteger(int.Parse(Console.ReadLine()));
  8. BigInteger a2 = new BigInteger(int.Parse(Console.ReadLine()));
  9. BigInteger a3 = new BigInteger(int.Parse(Console.ReadLine()));
  10. BigInteger n = new BigInteger(int.Parse(Console.ReadLine()));
  11.  
  12. if (n==1){Console.WriteLine(a1);}
  13. else if(n == 2){Console.WriteLine(a2);}
  14. else if (n == 3){Console.WriteLine(a3);}
  15. else
  16. {
  17. BigInteger total = 0;
  18. for (int i = 4; i <= n; i++)
  19. {
  20. total = a1 + a2 + a3;
  21. a1 = a2;
  22. a2 = a3;
  23. a3 = total;
  24. }
  25. Console.WriteLine(total);
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement