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"; }
Comments
Leave a comment