-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2darray.cpp
More file actions
51 lines (41 loc) · 825 Bytes
/
Copy path2darray.cpp
File metadata and controls
51 lines (41 loc) · 825 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
void printcol(int arr[][4]){
for(int j=0;j<4;j++){
for(int i=0;i<3;i++){
cout<<arr[i][j] <<" ";
}
}
}
bool linearsearch(int arr[][4],int row,int col,int target){
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
if(arr[i][j]==target){
return true;
}
}
}
return false;
}
int main(){
int arr[3][4];
int num=1;
for(int i=0;i<3;i++){
for(int j=0;j<4;j++){
arr[i][j]=num;
num++;
}
}
//to print all values
for(int i=0;i<3;i++){
for(int j=0;j<4;j++){
cout<<arr[i][j] <<" ";
}
}
//print via function column wise
printcol(arr);
//find an element in our array
int rows=3,col=4;
int X=7;//target
cout<< linearsearch(arr,rows, col, X);
}