Professional Documents
Culture Documents
LCS2022052 DAA Lab02
LCS2022052 DAA Lab02
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "Enter no of elements in the array ";
cin >> n;
int arr[n];
cout << "Enter array elements :";
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
int x;
cout << "Enter a no: ";
cin >> x;
int e = sizeof(arr) / sizeof(arr[0]);
int result = LinearSearch(arr, e, x);
if (result == -1)
{
cout << "Element is not present in array" << endl;
}
else
{
cout << "Element is present at index " << result << endl;
}
return 0;
}
Screen shot of the output: