Skip to main content

1D Arrays in C problem solution | HackerRank

1D Arrays in C problem solution | HackerRank

The first line contains an integer, .
The next line contains  space-separated integers.

Constraints


Output Format

Print in a single line the sum of the integers in the array.





#include <stdio.h>
#include <stdlib.h>

int main()
{
  
    int n, *arr, i, sum = 0;
    scanf("%d", &n);
    arr = (int*) malloc(n * sizeof(int));
    for(i = 0; i < n; i++) {
        scanf("%d", arr + i);
    }

    for(i = 0; i < n; i++) {
        sum += *(arr + i);
    }

    printf("%d\n", sum);
    free(arr);
    return 0;
}

Comments

Popular posts from this blog

Insertion Sort - Part 2 | C | HACKERRANK

Array Reversal problem solution | C | HackerRank

Insertion Sort - Part 1 | C | HackerRank |