Sum of Even Numbers
JavaScript
Easy
4 views
Problem Description
Given an array of integers, print the sum of only even numbers.
Input Format
One line: n then n integers.
Output Format
One integer sum.
Official Solution
const fs=require('fs');const a=fs.readFileSync(0,'utf8').trim().split(/\\s+/);if(a.length===0){process.exit(0);}let idx=0;const n=Number(a[idx++]);let sum=0n;for(let i=0;i<n;i++){const v=BigInt(a[idx++]);if(v%2n===0n)sum+=v;}process.stdout.write(String(sum));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!