본문 바로가기

문제풀이/C 문제풀이

[Hackerrank]A Very Big Sum

문제

Calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.

Function Description
Complete the aVeryBigSum function in the editor below. It must return the sum of all array elements.
aVeryBigSum has the following parameter(s):
ar: an array of integers .
Input Format
The first line of the input consists of an integer .
The next line contains space-separated integers contained in the array.
Output Format
Print the integer sum of the elements in the array.

CODE

long aVeryBigSum(int ar_count, long* ar) {
    long long int sum = 0;
    for (int i=0;i<ar_count;i++)
        sum += *(ar+i);
    return sum;
}

감상

long long int는 난생 처음 써 본다. 신기하다.

'문제풀이 > C 문제풀이' 카테고리의 다른 글

[HackerRank]Plus Minus  (0) 2019.05.24
[HackerRank]Diagonal Difference  (0) 2019.05.21
[Hackerrank]Compare the Triplets  (0) 2019.05.17
[HackerRank]Simple Array Sum  (0) 2019.05.17
1181  (0) 2019.03.01