cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Comparing elements in 2-dimens. array
Comparing elements in 2-dimens. array
Nov 19, 2014 at 2:00am UTC
krwlng49
(1)
Hello everybody,
I'm trying to improve my C++ skills on my own,
So I need a little bit help,
Hope you can help,here's my question:
I need to write a programm which can compare two elements in a two-dimensional array which is the following one:
int arr[4][2] = { {1,100},
{2,400},
{3,200},
{1,300} };
I have to add up the elents which have the same value of the
which have the same number in the first column;
for example: 1 -> 400 (100+300) / 2 -> 400 / 3 -> 200
But I have some problems in my code,here is what I could do so far:
for(int i=0;i<4;++i){
for(int j=0;j<2;++j){
if(arr[i][j]==arr[i+1][j]){ //elem. in same coulmn but diff. row
value = arr[i][j] + arr[i+1][j]; //values are added up
}
}
cout << " Value " << summe;
}
I would be thankful for every tip ;)
Last edited on
Nov 19, 2014 at 2:59am UTC
Topic archived. No new replies allowed.