Sir, my code is giving runtime error i don’t know why.
#include
using namespace std;
// code for linear search
int main() {
int n;
int a[n];
int key;
int i;
cout << "Enter the number of elements: " << endl;
cin >> n;
cout << "Enter key element: " << endl;
cin >> key;
for(int i=0; i<n; i++)
{
cin >> a[i];
}
for(int i=0; i<n; i++)
{
if(key==a[i])
{
cout << "Element found at index " << i << endl;
break;
}
if(i==n)
cout << "Element not found";
}
return 0;
}