A Very Big Sum
In this HackerRank A Very Big Sum problem solution In this challenge, you are required to calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.
Function Description
Complete the aVeryBigSum function in the editor below. It must return the sum of all array elements.
aVeryBigSum has the following parameter(s):
int ar[n]: an array of integers.
Return
long: the sum of all array elements
Input Format
The first line of the input consists of an integer n.
The next line contains n space-separated integers contained in the array.
Output Format
Return the integer sum of the elements in the array.
Solution (Base on how i solved it)
$bigNum = 0; //variable to hold results
$myarr = sizeof($ar); //counted how many field i have in the given array
for($i = 0; $i < $myarr; $i++){ //loop through the given array
$bigNum += $ar[$i]; //add each field to my result variable
}
return $bigNum; //here is my result
Link to HackerRank: A Big Sum Problem Test
Top comments (0)