alright here is my programming code.
// program 12.4.6
// author: mike morales
// objective: to take a two dimensional array,
// and then sort's it's elements in ascending order,
// and store them in a one dimensional array
#include <iostream>
#include<string>
using namespace std;
/*void SelectionSort(int array[],int g, int value1, int value2);*/
int Search( const int F[], int p, int Key){
for(int i=0;i<p;++i){
if(F==Key){
return i;
}
}
return p;
}
int main(){
int A[4][5] ={{16,22,99,4,18},{-258,4,101,5,98},{105,6,15,2,45},{33,88,72,16,3}}, B[100];
// no we are going to convert
int n;
cout <<" number of elements?" << endl;
cin >> n;
for (int r=0;r<4;++r){
for(int c=0;c<5;++c){
B[20]= A[r][c];
B[n]=B[20];
cout << B[n] << endl;
}
}
int Key;
cout << " enter search value " << endl;
cin >> Key;
int q = Search(B,n,22);
cout << q << endl;
return 0;
}
supposedly, the function search should return the matching subscript of that elements value. per se... i pick 22, it should return the address for that element which is 1...but i keep on getting a twenty!
is something wrong with my if statements or do i need to declare a new variable, instead of "n" in my search function?
plz help!
// program 12.4.6
// author: mike morales
// objective: to take a two dimensional array,
// and then sort's it's elements in ascending order,
// and store them in a one dimensional array
#include <iostream>
#include<string>
using namespace std;
/*void SelectionSort(int array[],int g, int value1, int value2);*/
int Search( const int F[], int p, int Key){
for(int i=0;i<p;++i){
if(F==Key){
return i;
}
}
return p;
}
int main(){
int A[4][5] ={{16,22,99,4,18},{-258,4,101,5,98},{105,6,15,2,45},{33,88,72,16,3}}, B[100];
// no we are going to convert
int n;
cout <<" number of elements?" << endl;
cin >> n;
for (int r=0;r<4;++r){
for(int c=0;c<5;++c){
B[20]= A[r][c];
B[n]=B[20];
cout << B[n] << endl;
}
}
int Key;
cout << " enter search value " << endl;
cin >> Key;
int q = Search(B,n,22);
cout << q << endl;
return 0;
}
supposedly, the function search should return the matching subscript of that elements value. per se... i pick 22, it should return the address for that element which is 1...but i keep on getting a twenty!
is something wrong with my if statements or do i need to declare a new variable, instead of "n" in my search function?
plz help!