Write a program that asks the user to enter up to 20 integers.Store the integers
ID: 3553902 • Letter: W
Question
Write a program that asks the user to enter up to 20 integers.Store the integers in
an array of longs.Then, the program should ask the user to enter an integer.The
program should use the function Find_It()to locate the integer in the array.The
third argument in Find_It() is the address of the found integer. The function
should return 1 if the integer is found and 0 otherwise. If the integer is found, the
program should replace the integer by its negative and display the elements in
the array. If the integer is not found, display an appropriate message.
Explanation / Answer
#include <iostream>
using namespace std;
int Find_It(long a[], int size, int *found){
int i, j;
for(i = 0; i < size; i++){
if(a[i] == *found){
a[i] *= -1;
cout << "The elements are: ";
for(j = 0; j < size; j++){
cout << a[j] << " ";
}
cout << " ";
return 1;
}
}
cout << "Number " << *found << " not found ";
return 0;
}
int main(){
int i, n = 1, x;
cout << "How many integers do you want in the array? ";
cin >> n;
long array[n];
cout << "Enter " << n << " integers: ";
for(i = 0; i < n; i++){
cin >> array[i];
}
cout << "Enter the integer you want to find: ";
cin >> x;
Find_It(array, n, &x);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.