Given an array of integers, find the sum of its elements.
For example, if the array,, so return.
Function Description
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
21
ed oot.
manna
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
Constraints
Output Format
Print the sum of the array's elements as a single integer.
Sample Input
6
1234 10 11 Sample Output
31
Explanation
We print the sum of the array's elements:.
Output:
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:
Copy code
`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:
Copy code
`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.