#include <stdio.h>
#include <stdbool.h>
#define ROWS 7
#define COLS 3
// Function to compare two rows of a matrix
bool areRowsEqual(int* row1, int* row2, int cols) {
for (int j = 0; j < cols; j++) {
if (row1[j] != row2[j]) {
return false;
}
}
return true;
}
// Function to find and print repeated rows of a matrix
void findRepeatedRows(int matrix[][COLS], int rows, int cols) {
printf("Repeated rows:\n");
for (int i = 0; i < rows; i++) {
for (int j = i + 1; j < rows; j++) {
if (areRowsEqual(matrix[i], matrix[j], cols)) {
printf("Row %d is the same as Row %d\n", i, j);
}
}
}
}
int main() {
int matrix[ROWS][COLS] = {
{1, 2, 3},
{4, 5, 6},
{1, 2, 3},
{7, 8, 9},
{4, 5, 6},
{0, 1, 2},
{4, 5, 6}
};
findRepeatedRows(matrix, ROWS, COLS);
return 0;
}
/*
run:
Repeated rows:
Row 0 is the same as Row 2
Row 1 is the same as Row 4
Row 1 is the same as Row 6
Row 4 is the same as Row 6
*/