#include <iostream>
usingnamespace std;
int answer(int asd[], int num);
int main (){
int numbers[5]={1,5,42,68,85};
int total=answer(numbers,5);
cout << "sum of all elements in the array " << total << endl;
system("pause");
return 0;
}
int answer(int asd[], int num){
int sum=0;
for(int x=0;x<num;x++){
sum+=asd[x];
}
return sum;
}
If the x value is 5 how can asd[x] at line17 be the result of the sum of all the numbers?.
Thanks, that helped. Just to be sure, the value asd is basically (1,5,42,68,85), the value num is 5, when i for loop i execute 5 times x (0,1,2,3,4) and then by putting x to asd i make 1,5,42,68,85 (5 numbers) executing, having the result.