Given an array of integers, find the sum of its elements.
For example, if the array,, so return.
Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.
simpleArraySum has the following parameter(s):
ar: an array of integers Input Format
The first line contains an integer,, denoting the size of the array. The second line contains space-separated integers representing the array's elements. arks
Print the sum of the array's elements as a single integer.
1234 10 11 Sample Output
We print the sum of the array's elements:.
To find the sum of the elements in an array, you can use a loop to iterate through the elements of the array and add them up.
Here is an example of how you could do this in Python:
`def simpleArraySum(ar): sum = 0 for i in range(len(ar)): sum += ar[i] return sum`
This function takes in an array `ar` and uses a loop to iterate through the elements of the array. For each element, it adds it to the variable `sum`. At the end, it returns the sum.
You can then call this function and pass in your array as an argument, like this:
`result = simpleArraySum([1, 2, 3, 4, 10, 11]) print(result) # Output: 31`
This would output the sum of the elements in the array, which is 31.