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
|
#include <iostream>
using namespace std;
int sortedArray[10] = {0,1,2,3,4,5,6,7,8,9};
void findIndex(int array[], int searchValue, int index);
void findIndex(int array[], int searchValue, int index){
if(searchValue == array[index]){
cout << "The index of the value is: " << index << endl;
}else if(index = 9){
cout << "The number was not found" << endl;
}else
findIndex(array, searchValue, index+1);
}
int main(){
findIndex(sortedArray, 10, 0);
system("pause");
}
|