Answer to Question #319267 in C++ for Mamo debela

Question #319267

Write a c++ program using function that take an array of integers as input and return the

sum of number in the array.


1
Expert's answer
2022-03-28T02:29:34-0400
#include <iostream>


using namespace std;




int sum(int *array, int length) {
    int sum = 0;
    for (int i = 0 ; i < length; i++) {
        sum += array[i];
    }
    return sum;
}






int main() {
    int length;
    cout << "Enter array length: ";
    cin >> length;
    int *array = new int[length];
    for (int i = 0; i < length; i++) {
        cout << "\nEnter "<< i+1 <<" element of array : ";
        cin >> array[i];
    }


    cout << "\nSum of number in the array: "<<sum((array),length);


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog