Running Counter
PHP
Easy
4 views
Problem Description
You are given n and then n integers. Start total=0. Add each value and print final total.
Input Format
First n. Next line has n integers.
Output Format
One integer total.
Official Solution
<?php
$inputText=trim(stream_get_contents(STDIN));
if($inputText==='') exit;
$tokens=preg_split('/\\s+/', $inputText);
$i=0; $n=intval($tokens[$i++] ?? 0);
$sum=0;
for($k=0;$k<$n;$k++) $sum+=intval($tokens[$i++] ?? 0);
echo $sum;
?>
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!