Discover the best answers at Westonci.ca, where experts share their insights and knowledge with you. Explore our Q&A platform to find reliable answers from a wide range of experts in different fields. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals.
Sagot :
Answer:
In C++:
#include <iostream>
using namespace std;
int main(){
int myArray[10] = {000, 101, 202, 303, 404, 505, 606, 707, 808, 909};
int num;
bool found = false;
cout<<"Search for: ";
cin>>num;
for(int i = 0;i<10;i++){
if(myArray[i]==num){
found = true;
break;
}
}
if(found){ cout<<"found"; }
else { cout<<"not found"; }
return 0;
}
Explanation:
This line initializes the array
int myArray[10] = {000, 101, 202, 303, 404, 505, 606, 707, 808, 909};
This line declares num as integer
int num;
This initializes boolean variable found to false
bool found = false;
This prompts user for input
cout<<"Search for: ";
This gets user input
cin>>num;
This iterates through the array
for(int i = 0;i<10;i++){
This checks if num is present in the array
if(myArray[i]==num){
If yes, found is updated to true
found = true;
And the loop is exited
break;
}
}
If found is true, print "found"
if(found){ cout<<"found"; }
If found is false, print "not found"
else { cout<<"not found"; }
Thanks for using our platform. We aim to provide accurate and up-to-date answers to all your queries. Come back soon. We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. Your questions are important to us at Westonci.ca. Visit again for expert answers and reliable information.