Suppose an integer array A has been declared and initialized for you, and you do
ID: 3529375 • Letter: S
Question
Suppose an integer array A has been declared and initialized for you, and you don't know the length. Write a code fragment to input an integer from the console, search the array, and output "YES" if the input value was found in the array, and "NO" if not. Instructor's notes: Use the "sizeof" pattern we learned in class to compute the length N of the array. Declare all variables you need, including N. HINT: the solution is more difficult than finding the largest / smallest element, so you need to take a slightly different approach in this case. A simple if-then-else inside the loop will not work...Explanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int A[]={3,4,5,6,3,55,43,32,3433,34};
int n =sizeof (A) / sizeof( A[0]);
int num;
int found=0;
cout<<"Enter value to search for: ";
cin>>num;
for(int i=0;i<N;i++){
if(A[i]==target){
found=1;
break;
}
}
if(found==1)
cout<<"YES";
else
cout<<"NO";
return 0;
}