Sum of array elements

Beginner Problems Basic Arrays Easy
  • This seemingly simple programming problem, calculating the sum of all elements in an array, has powerful real-world applications
  • For example, it's used in the creation of statistical software and data analysis applications, such as Excel and Google Sheets
  • Developers utilize this concept to implement features that enable users to sum up large columns or rows of numerical data in these spreadsheet applications, facilitating businesses and researchers to quickly perform financial or scientific calculations

Given an array arr of size n, the task is to find the sum of all the elements in the array.

Examples:

Input: n=5, arr = [1,2,3,4,5]


Output: 15


Explanation: Sum of all the elements is 1+2+3+4+5 = 15

Input: n=6, arr = [1,2,1,1,5,1]


Output: 11


Explanation: Sum of all the elements is 1+2+1+1+5+1 = 11

Input: n=3, arr = [2,1,1]

Constraints

  • 1 <= n <= 105
  • 1 <= arr[i] <= 104

Company Tags

TCS Cognizant Accenture Infosys Capgemini Wipro IBM HCL Tech Mahindra MindTree