how to acces alternate element of a 2D array

Hello Everybody

I want to print the value of alternative element of a 2D array.
For Example-
23, 54, 76
37, 19, 28
62, 13, 19

Output should be-
23 76 19 62 19

I am trying to get this output since 5 hours. Here is my code -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream.h>
#include <conio.h>
void process_Array(int Arr[][3],int x, int y);
void process_Array(int A[][3],int N, int M)
{
	clrscr();
	for (int R = 0; R < N; R++)
	{
		for (int C = 0; C < M; C=C+2)
		{
			cout<< A[R][C]<<" ";
		}
	}
	cout<<endl;
	cout<<endl;
	for (int I = 0; I < N; I++)
	{
		for (int J = 0; J < M; J++)
		{
			cout << A[I][J]<<" ";
		}
	cout<<endl;
	}
}
int main()
{
	int arr[3][3] ={
	{23, 54, 76},
	{37, 19, 28},
	{62, 13, 19},
};
process_Array(arr,3,3);  
return 0;
}

By this code I am getting this output -
23 76 37 28 62 19, actually there must be 19 which is arr[1,1].

Please advice me.
Thank you.
C=C+2 is always going to give you 0th and 3rd element. If you increase the size to 5 then its going to give you 0th, 3rd, 5th and so on
Topic archived. No new replies allowed.