C Online Compiler
Example: Brute Force Search in Sorted Matrix in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Brute Force Search in Sorted Matrix #include <stdio.h> void searchMatrixBruteForce(int matrix[4][4], int rows, int cols, int target) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { if (matrix[i][j] == target) { printf("Target %d found at (%d, %d)\n", target, i, j); return; } } } printf("Target %d not found in the matrix\n", target); } int main() { int matrix[4][4] = { {10, 20, 30, 40}, {15, 25, 35, 45}, {27, 29, 37, 48}, {32, 33, 39, 50} }; int rows = 4; int cols = 4; int target1 = 37; int target2 = 31; // Step 1: Search for target1 searchMatrixBruteForce(matrix, rows, cols, target1); // Step 2: Search for target2 searchMatrixBruteForce(matrix, rows, cols, target2); return 0; }
Output
Clear
ADVERTISEMENTS