Write the code for the following problem using either C or C++. If there are 8 cars with its car number {11,10,34,56,68,89,65,78} parked in a parking area, then you are looking for a car number 68 by checking every car sequentially from the beginning.
#include <iostream>
using namespace std;
int Search(int arr[], int num){
for(int i=0;i<8;i++){
if(arr[i] == num){
return 1;
}
}
return -1;
}
int main()
{
int arr[8]={11,10,34,56,68,89,65,78};
int num=68;
int r=Search(arr,num);
if (r==1)
cout<<"Search number is found!!!";
else
cout<<"Search number is not found";
return 0;
}
Comments
Leave a comment