I am writing a program that accepts an input and i would like to process it in the below fashion:
Question:
input :
1 2 4 5
3 4 5 6
7 2 4 5 1 2
1 2 4 3 4 5 5
I want to get the sum of the columns and the rows like”
sum of rows:
12
18
21
etc
sum of columns:
12
10
17
etc
And then I want to store them in an array for later use.
How do I achieve this?
My approach:
I have managed to get the sum of rows in the below manner:
istringstream iss(line);
int i = 0;
int sum = 0;
while (iss >> i)
{
sum += i;
numberOfColumns ++ ;
}
I am stuck on how to get the sum of columns.
Assume: That the number of columns is fixed Note: This is not an academic exercise, this is an extension of this question: Sum all integers in a string C++
Thank you