Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int arrSize{ 10 };
- int arr[arrSize]{10,12,3,8,15,2,17,1,3,10};
- int key{ 100 };
- int foundIdx{ -1 };
- for (int i{ 0 }; i < arrSize; ++i)
- {
- std::cout << arr[i] << ' ';
- }
- std::cout << '\n';
- for (int i{ 0 }; i < arrSize; ++i)
- {
- if (arr[i] == key) { foundIdx = i; break; }
- }
- if (foundIdx >= 0)
- {
- std::cout << "Key " << key << " was found on index " << foundIdx << '\n';
- }
- else
- {
- std::cout << "Key " << key << " was not found!\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment