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 main(){
int index;
int cars[8] = {11,10,34,56,68,89,65,78};
for(int i=0; i<8; i++){
if(cars[i]==68){
index = i;
}
}
cout<<"The position of car number 68 is at "<<index + 1<<endl;
}
Comments
Leave a comment