There is a task: To write a program for processing data organized in an array, according to the task of the above option. In programs, use various forms of addressing elements of multidimensional arrays, including using the pointer to array and pointer to pointer constructs. Take into account that each row of the matrix can be processed as a separate element. Enter a rectangular matrix of integers. Print the row numbers of the matrix, all elements of which are odd (or print a message about the absence of such rows). Rearrange the elements of all other lines in reverse order.

To perform a complete task, I did everything except for one: create a pointer to the element of a multidimensional array, and use it.

All program code:

DEFINE ROWS 3 DEFINE COLS 4

 int main() { int iMatrix[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { scanf("%d", &iMatrix[i][j]); } } printf("\n"); int status = 0; int Odds = 0; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { if (iMatrix[i][j]%2==1) { status = 1; } else { status = 0; break; } } if (status == 1) { printf("[%d] Row have all odd elements\t\t\t\t\t ", i + 1); for (int j = 0; j < COLS; j++) { printf("%d\t", iMatrix[i][j]); Odds++; } printf("\n"); } else { printf("[%d] Row which have all pair elements written at inverse direction: ", i+1); for (int j = COLS-1; j >=0 ;j--) { printf("%d\t", iMatrix[i][j]); } printf("\n"); continue; } } if (Odds == 0) printf("There aren't rows with all odd elements.\n"); printf("\nYour input:\n"); for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { printf("%d\t", iMatrix[i][j]); } printf("\n"); } _getch(); return 0; } 

After the code tried to create a pointer to an array, it gives errors

What could be the error?

 int memory = sizeof(iMatrix) / sizeof(int); int* ptr; for (ptr = (int*)iMatrix; ptr < (int*)iMatrix + memory; ptr++) { scanf("%d", (int*)iMatrix); } 

Closed due to the fact that off-topic participants ߊߚߤߘ , αλεχολυτ , Mikhail Vaysman , Denis Bubnov , m9_psy Apr 22 '17 at 14:09 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - ߊߚߤߘ, αλεχολυτ, Mikhail Vaysman, Denis Bubnov
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Nothing is clear. What is "after code"? - AnT

1 answer 1

 for( int i = 0; i < ROWS; i++ ) { /* ptr - указатель на массив: */ int *ptr = iMatrix[i]; for( int j = 0; j < COLS; j++ ) { printf( "%d ", *( ptr + j ) ); } printf( "\n" ); }