Answer to Question #319171 in C++ for mak

Question #319171

Write a program that takes an array ‘A’ of size 10 and an integer ‘x’ as input and searches the index of ‘x’ in the array. If ‘x’ is found, print the index. If ‘x’ is not found, then print -1. If ‘x’ is present two or more than two times in the array, then print the index of last occurrence of ‘x’.

1
Expert's answer
2022-03-27T13:17:33-0400


#include <iostream>


using namespace std;










int main(void){
	int A[10];
	int index=-1;
	int x;
	for(int i=0;i<10;i++){
		cout<<"Enter the number "<<(i+1)<<": ";
		cin>>A[i];
	}




	cout<<"Enter x: ";
	cin>>x;
	for(int i=0;i<10;i++){
		if(x==A[i]){
			index =i;
		}
	}




	cout<<"The index: "<<index<<"\n";




	system("pause");
	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