Advertisement
R3v3rs3r

Array linear search [C++]

Oct 10th, 2023
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | Source Code | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int arr[10], i, num, index;
  8.     cout<<"Enter 10 numbers:\n";
  9.     for(i=0; i<10; i++) {
  10.         cin>>arr[i];
  11.     }
  12.     cout<<"\nEnter a number to search: ";
  13.     cin>>num;
  14.     for(i=0; i<10; i++)
  15.     {
  16.         if(arr[i]==num) {
  17.             cout<<"\nFound at index no. "<<i;
  18.             break;
  19.         }
  20.     }
  21.     if(i==10) {
  22.         cout<<"\nElement not present in the array.";
  23.     }
  24.     getch();
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement