Question

Write a function named findTarget that takes three parameters: - numbers, an array of integers -...

Write a function named findTarget that takes three parameters:
- numbers, an array of integers
- size, an integer representing the size of array
- target, a number
The function returns true if the target is inside array and false otherwise

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:-

#include <iostream>
using namespace std;
bool findTarget(int arr[],int n,int t);

int main(){
int num,t;
bool flag;
cout<<"enter teh size of array : ";
cin>>num;
int arr[num];
cout<<"enter elements of the array : ";
for(int i=0;i<num;i++)
cin>>arr[i];
cout<<"enter target number : ";
cin>>t;
flag = findTarget(arr,num,t);
if (flag==true)
cout<<t<<" is available in array !";
else
cout<<t<<" is not not available in array !";
return 0;
}
bool findTarget(int arr[],int n,int t){ // question reqirement function
for(int i = 0; i < n; i++) {
if(t == arr[i]) {
return true;
break;
}
}
return false;
}

// OUTPUT

Success #std in #stdout 0s 4512KB enter teh size of array 5 enter elements of the array 6 9 2 18 enter target number: 1 1 is

// Please vote

Add a comment
Know the answer?
Add Answer to:
Write a function named findTarget that takes three parameters: - numbers, an array of integers -...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT