Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The below code is giving me errors, any help would be appreciated. #include <cst

ID: 3605468 • Letter: T

Question

The below code is giving me errors, any help would be appreciated.

#include <cstdlib>
#include <iostream>

using namespace std;

int arraysum(int arr[], int n)
{
if (n<0)
return 0;

else
return (arr[n]+arraysum(arr, n-1));

}

int main()
{
int array[100], sum=0, n;

cout << "Enter the Value of N";
cin >> n;

cout << endl << "Enter the Values into the array";
for (int i=0; )

cin>> array[i];

sum=arraysum(array, n-1);

cout << "Sum of Array is:" << sum << endl;

system("PAUSE");
return 0;
}

Explanation / Answer

#include <cstdlib>
#include <iostream>
using namespace std;
int arraysum(int arr[], int n)
{
if(n<0)
return 0;
else
return (arr[n]+arraysum(arr, n-1));
}
int main()
{
int array[100], sum=0, n;
cout << "Enter the Value of N";
cin >> n;
cout << endl << "Enter the Values into the array";
//loop condition and loop incrementation is not written (i<n;i++).
for (int i=0;i<n;i++)
cin>> array[i];
sum=arraysum(array, n-1);
cout << "Sum of Array is:" << sum << endl;
system("PAUSE");
return 0;
}
/*
sample output
Enter the Value of N 5

Enter the Values into the array 1
2
3
4
5
Sum of Array is:15
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote