Question: Correct my mistake #include using namespace std; int SearchPerfectValue ( int a [ ] , int n , int val ) { int i; for

Correct my mistake #include
using namespace std;
int SearchPerfectValue(int a[], int n, int val)
{
int i;
for (i =0; i < n; i++)
{
if (a[i]== val) return i;
}
return -1;
}
void ShowArray(int a[], int n)
{
int i;
for (i =0; i < n; i++)
{
cout << a[i]<<"";
}
cout << endl;
}
int main()
{
int a[1000]; //reserve 1000 index position
int val, n, founf;
cout << "Enter Array Size between 1 to 1000: "<< endl;
cin >> n;
srand(time(0));
for (int i =0; i < n; i++)
{
a[i]= rand()%1000; //populate the array in order
}
cout << "Elements of the array; "<< endl;
ShowArray(a, n);
cout <<"
Enter a search perfect value: "<< endl;
cin >> val;
found = SearchPerfectValue(a, n, val);
if (found !=-1)
{
cout << "The search value was found at index position: "<< found <<"."<< endl;
}
else
{
cout << "The search value was not found." << endl;
}
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!