Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<iostream>
- using namespace std;
- bool linearSearch(int arr[], int size, int target)
- {
- for(int i=0;i<size;i++)
- {
- if(arr[i]==target)
- {
- return true;
- }
- }
- return false;
- }
- void searchNumberInArray()
- {
- int numbers[100], n;
- cout << "Enter the number of elements in the array: ";
- cin >> n;
- cout << "Enter " << n << " numbers: ";
- for(int i = 0; i < n; i++)
- {
- cin >> numbers[i];
- }
- int searchNumber;
- cout << "Enter a number to search: ";
- cin >> searchNumber;
- if(linearSearch(numbers, n, searchNumber))
- {
- cout << "Yes, the number is found in the array." << endl;
- }
- else
- {
- cout << "No, the number is not found in the array." << endl;
- }
- }
- int main()
- {
- searchNumberInArray();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement