Sum Until Zero
JavaScript
Easy
4 views
Problem Description
Input has integers separated by spaces/new lines. Keep adding until you see 0. Print the sum (0 is not included).
Input Format
Many integers (space/newline).
Output Format
One integer sum.
Constraints
At least one 0 will appear.
Official Solution
const fs=require('fs');const a=fs.readFileSync(0,'utf8').trim().split(/\\s+/);if(!a[0])process.exit(0);let sum=0n;for(const t of a){const v=BigInt(t);if(v===0n)break;sum+=v;}process.stdout.write(sum.toString());
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!