Answer to Question #31325 in C++ for Ithamar

Question #31325
write a function that takes 3 parameters: an array,its size and an integer.This function should return true if that integer was found in that array,false otherwise.Write a program that asks the user to enter 5 numbers and save then in an array ARR.Ask the user to enter an integer,use the function above to check if that integer was found in the array ARR.
1
Expert's answer
2013-05-28T08:03:27-0400
#include <iostream>
#include <conio.h>

using namespace std;

//function check if integer is in array
bool findInteger(int ARR[],int size,int integernumber){
bool find =false;
for(int i=0;i<size;i++){
if(integernumber==ARR[i]){
find =true;
break;
}
}
return find;
}
//mai function
int main()
{
int ARR[100];//array
int integer;//integr number
for(int i=0;i<5;i++){
cout<<"Enter number "<<(i+1)<<":
";//input number
cin>>ARR[i];//read number
}
//
cout<<"Enter intger: ";
cin>>integer;
//show result
if(findInteger(ARR,5,integer)==true){//r,use the function above to check if
that integer was found in the array ARR.
cout<<"This integer was found in the array ARR.";
}else{
cout<<"This integer was not found in the array ARR";
}

getch();//delay
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
APPROVED BY CLIENTS