Answer to Question #236020 in C++ for Rahul

Question #236020

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.


1
Expert's answer
2021-09-11T23:39:29-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS