0% found this document useful (0 votes)
19 views

Sum CPP

The document contains C++ code that defines a function to add elements of an array and calls it from main to calculate the sum of user-input numbers stored in an array.

Uploaded by

H Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Sum CPP

The document contains C++ code that defines a function to add elements of an array and calls it from main to calculate the sum of user-input numbers stored in an array.

Uploaded by

H Hassan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

using namespace std;

int add(int[]);

int main()

int arr[5];

for (int i = 0; i < 5; i++)

cout << "Please eneter a number: ";

cin >> arr[i];

cout << endl;

int sum = add(arr);

cout << "Sum = " << sum;

return 0;

int add(int m[])

int sum = 0;

for (int i = 0; i < 5; i++)


{

sum += m[i];

return sum;

You might also like