Advertisement
coasterka

ExamTaskJudgeProblem.js

Jul 22nd, 2014
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Solve(args) {
  2.     var x = parseInt(args[0]);
  3.     var y = parseInt(args[1]);
  4.     var z = parseInt(args[2]);
  5.     var n = parseInt(args[3]);
  6.     var result;
  7.    
  8.     if (n === 1) {
  9.         result = x;
  10.     }
  11.     else if (n === 2) {
  12.         result = y;
  13.     }
  14.     else if (n === 3) {
  15.         result = z;
  16.     }
  17.     else {
  18.         for (var i = 4; i <= n; i++) {
  19.             var temp = x + y + z;
  20.             x = y;
  21.             y = z;
  22.             z = temp;
  23.         }
  24.         result = temp;
  25.     }
  26.     return result;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement