#include <iostream>
usingnamespace std;
int add_arrays(int a[], int b[], int n);
int main ()
{
int b [5]={1,2,3,4,5};
int a [5] ={1,2,3,4,5};
int total= add_arrays(a,b, 5);
cout << total << endl;
}
int add_arrays(int a[], int b[], int n)
{
int z = 0;
for (int i = 0; i < n; i++)
{
z+= a[i] + b[i];
}
return 0;
}
Can someone kinda check this one to see what wrong with it?
#include <iostream>
usingnamespace std;
int ture ( int a[], int b[], int d);
int main ()
{
int b [5]={1,2,3,4,5};
int a [5] ={1,2,3,4,5};
int total= ture(b, a, 5);
cout << total << endl;
}
int ture ( int a[], int b[], int d)
{
constdouble NUM = 10;
for (int d = 0; d < 10; d++)
{
if (a[d] != b[d])
{
returnfalse;
}
}
returntrue;
}
The initializer of total is zero because the value returned by the add_arrays function is always zero. Replace the return statement within add_arrays's compound statement with return z; to fix the problem.
1 2 3 4 5 6 7 8 9 10 11
int add_arrays(int a[], int b[], int n)
{
int z = 0;
for (int i = 0; i < n; i++)
{
z+= a[i] + b[i];
}
return z;
}