Simple Array Sum - Hackerrank Solution

 


Simple Array Sum


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

The first line contains an integer, n, denoting the size of the array.
The second line contains n space-separated integers representing the array's elements.

Constraints

Output Format

Print the sum of the array's elements as a single integer.

Sample Input


6

1 2 3 4 10 11


Sample Output


31


Explanation:

We print the sum of the array's elements: 1 + 2 + 3 + 4 + 10 + 11 = 31


  • Solution:
n=int(input())
s=0;t=[]
a=input()
a=a.split()
for i in a:
    s=s+int(i)
print(s)

  • Note:

    Note:

    This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.

    Disclaimer:-

    The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

    Simple Array Sum - Hackerrank Solution Simple Array Sum - Hackerrank Solution Reviewed by CodexRitik on November 16, 2020 Rating: 5

    2 comments:

    1. Interesting problem, learning and solving computational problem is the most effective way to learn programming. Core concepts of computer science such as algorithms, data structures, memory etc. are helpful in this. Thank you for sharing this. Find Google interview questions algorithms to prepare well for your next coding interview.

      ReplyDelete

    Powered by Blogger.