JcGaming

act#3 dsa john carl quieta

Nov 7th, 2023 (edited)
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | Source Code | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int myArray[] = {2,7,8,13,5,9};
  6.     int n;
  7.     bool search= false;
  8.  
  9.     cout << "Choose number: ";
  10.     cin >> n;
  11.  
  12.     for(int i = 0; i < sizeof(myArray)/sizeof(myArray[0]); i++) {
  13.         if(myArray[i] == n) {
  14.             search = true;
  15.             cout << "Index " << n << " is: " << i << endl;
  16.             break;
  17.         }
  18.     }
  19.  
  20.     if(!search)
  21.         cout << n << " not found" << endl;
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment