#include <iostream>
using namespace std;
int main()
{
const int size = 10;
int arr[size];
// init array with sequence
for(int i = 0; i < size; i++)
arr[i] = i;
// print array
cout << "Array: ";
for(int i = 0; i < size; i++)
cout << arr[i] << " ";
cout << "\n";
int key, found = -1;
cout << "Enter the searched value\n";
cin >> key;
for(int i = 0; i < size && found == -1; i++) {
if( arr[i] == key ) {
found = i;
}
}
if( found == -1) {
cout << "Can't find the given number!\n";
} else {
cout << "Key "<< key << " is at " << found + 1 << "'th place in the array\n";
}
return 0;
}
Comments
Leave a comment