fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[5] = {10, 20, 30, 40, 50};
  6. int value;
  7. bool found = false;
  8.  
  9. cout << "Enter number: ";
  10. cin >> value;
  11.  
  12. for (int i = 0; i < 5; i++) {
  13. if (arr[i] == value) {
  14. cout << "Found at index " << i;
  15. found = true;
  16. break;
  17. }
  18. }
  19.  
  20. if (!found) {
  21. cout << "Not Found";
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5288KB
stdin
20
stdout
Enter number: Found at index 1