0% found this document useful (0 votes)
15 views2 pages

Linear Search 2d Array

Uploaded by

markoskadiu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Linear Search 2d Array

Uploaded by

markoskadiu7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// Online C++ compiler to run C++ program online

#include <iostream>
using namespace std;
int linear2dsearch(int arr[][5], int cols,int rows, int vlera,int &airreshta, int
&aikolona){
for(int i = 0; i<cols ; i++){
for(int j = 0; j<rows; j++){
if(arr[i][j] == vlera){
aikolona = i;
airreshta = j ;
return true;
}
}

}
return false;
}

int main() {
const int cols = 5;
const int rows = 5;
int arra[cols][rows];

int kolona;
int rreshta;

cout << "Ju loutem vendosni numrin e kolonave: ";


cin >> kolona;
cout << endl;
cout << "Vendosni numrin e rreshtave: ";
cin >> rreshta;
for (int i = 0; i < rreshta; i++) {
for (int j = 0; j < kolona; j++) {
cout << "Vendos vleren [" << i << j << "]";
cin >> arra[i][j];
}
}
cout<<endl<<endl;
cout<<"► ";
for (int j = 0; j < kolona; j++) {
cout<<" "<<j+1<<" ";
}
cout<<endl;

for (int i = 0; i < rreshta; i++) {


cout<<i+1<<" ";
for (int j = 0; j < kolona; j++) {
cout << "[" << arra[i][j] << "]";
}
cout << endl;
}
cout << endl;
int vlera;
cout << "Vlenndosni vleren qe doni te kerkoni: ";
cin >> vlera;
int airreshti, aikolonat;

if (linear2dsearch(arra, kolona, rreshta, vlera, airreshti, aikolonat)) {


cout << "Vlera qe kerkon ndodhet ne qelizen: [" << airreshti+1<< ":" <<
aikolonat+1 << "]" << endl;
} else {
cout << "Vleraqe kerkove nuk gjendet. ";
}

return 0;
}

You might also like