08
Jan
2020

Hackerrank Simple Array Sum (C++)

C++ :

int simpleArraySum(vector<int> ar) {
    /*
     * Write your code here.
     */
    int sum = 0;
    for(int i = 0; i < ar.size(); i++){
        sum += ar[i];
    }

    return sum;
}

Explanation:

Missed this all the way till the last warmup challenge. This is simple, simply adding up all the elements of a vector in sum, then returning it. Nothing much to say here, really.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *