You are given an array of integers. Your task is to calculate the sum of all elements present in the array and return the sum.
Example 1
Input: arr[] = [1 2 3 4 5]
Output: 15
Explanation: 1 + 2 + 3 + 4 + 5 = 15
Example 2
Input: arr[] = [10 20 30]
Output: 60
Explanation: 10 + 20 + 30 = 60
Example 3
Input: arr[] = [5 -2 7]
Output: 10
Explanation: 5 + (-2) + 7 = 10
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
2 4 6 8 10
30
99 11 77
187