Computer Guy
asked on
Add values of each row in an array
Hello,
Not sure where I am going wrong, but I want to display the sum of each row of the array:
Not sure where I am going wrong, but I want to display the sum of each row of the array:
#include <iostream>
using namespace std;
int main() {
int sum = 0;
int i, j,val[3][4] = {8, 16, 9, 52, //85
3, 15, 27, 6, //51
14, 25, 2, 10}; //51
i = 0;
for (j = 0; j < 4; j++)
sum = sum+ val[i][j];
cout << "The value of row 1 is " << sum << endl;
cout << "The value of row 2 is " << sum << endl;
cout << "The value of row 3 is " << sum << endl;
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
Open in new window
http://www.cplusplus.com/reference/numeric/accumulate/?kw=accumulate