-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_62.c
More file actions
37 lines (33 loc) · 951 Bytes
/
Copy pathProgram_62.c
File metadata and controls
37 lines (33 loc) · 951 Bytes
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
35
36
37
// Program 62: Write a program to search an element in a 2D array.
#include<stdio.h>
int main(){
int row , col;
printf("Enter the number of row for matrix : ");
scanf("%d",&row);
printf("Enter the number of col for matrix : ");
scanf("%d",&col);
int matrix[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
printf("Enter matrix[%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
int search ;
printf("Enter the number to be search : ");
scanf("%d",&search);
int found = 0;
// Search element
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (matrix[i][j] == search) {
printf("Element found at row %d and column %d\n", i, j);
found = 1;
}
}
}
if (!found) {
printf("Element not found in the matrix.");
}
return 0;
}