Created
September 28, 2017 03:34
-
-
Save juliaamosova/5412a28d0521cb33b2cb9f03261d54be to your computer and use it in GitHub Desktop.
Given an array of integers N, find the sum of its elements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.stdin.resume(); | |
process.stdin.setEncoding('ascii'); | |
var input_stdin = ""; | |
var input_stdin_array = ""; | |
var input_currentline = 0; | |
process.stdin.on('data', function (data) { | |
input_stdin += data; | |
}); | |
process.stdin.on('end', function () { | |
input_stdin_array = input_stdin.split("\n"); | |
main(); | |
}); | |
function readLine() { | |
return input_stdin_array[input_currentline++]; | |
} | |
/////////////// ignore above this line //////////////////// | |
function simpleArraySum(n, ar) { | |
// Complete this function | |
var tempSum = 0; | |
for (var i = 0; i < ar.length; i++) { | |
tempSum = tempSum + ar[i]; | |
} | |
return tempSum; | |
} | |
function main() { | |
var n = parseInt(readLine()); | |
ar = readLine().split(' '); | |
ar = ar.map(Number); | |
var result = simpleArraySum(n, ar); | |
process.stdout.write("" + result + "\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment