Guest User

Untitled

a guest
Sep 20th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main(void) {
  7.  
  8. int index = -1, key, i;
  9.  
  10. cout << "Enter key:";
  11. cin >> key;
  12.  
  13. const int N = 10;
  14. int a[N] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  15.  
  16. for (i = 0; i < N; i++) {
  17. if (key == a[i]) { index = i; break; }
  18. }
  19.  
  20. if (index >= 0) {
  21. cout << "Found index: " << index << "\n";
  22. }
  23. else {
  24. cout << "Not found index\n";
  25. }
  26. system("pause");
  27. return 0;
  28. }
Add Comment
Please, Sign In to add comment