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); }