Answer to Question #245643 in C++ for xtian

Question #245643

Write a program that will enter integers into the array then search for an element inside the array. The program should tell the location where the element was found. The user will be the one to determine the number of integers to be entered into the array.


1
Expert's answer
2021-10-02T07:24:29-0400
#include <iostream>


using namespace std;




int main(){
	int Array1[100];
	int number;
	cout<<"Enter a number of integers: ";
	cin>>number;
	for(int i=0;i<number;i++){
		cout<<"Enter integer value "<<(i+1)<<" for Array1: ";
		cin>>Array1[i];
	}
	int index=-1;
	int target;
	cout<<"Enter a target: ";
	cin>>target;
	for(int i=0;i<number;i++){
		if(target==Array1[i]){
			index=i;
		}
	}
	if(index!=-1){
		cout<<"A value "<<target<<" exist at index "<<index<<"\n";
	}else{
		cout<<"A value "<<target<<" does not exist\n";
	}
	
	 
	cin>>index;
	return 0;


}

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