write a program that ask the user to enter up to 20 integers. Store the integers
ID: 3641555 • Letter: W
Question
write a program that ask the user to enter up to 20 integers. Store the integers in an array of longs. Then, 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.h>
int Found_IT(signed long int arr[],signed long int x,signed long int **p);
int main()
{
signed long int arr[30],x,*p;
signed long int **q;
q=&p;
p=NULL;
cout<<"enter 20 integers"<<endl;
for(int i=0;i<20;i++)
cin>>arr[i];
cout<<"enter integer to search"<<endl;
cin>>x;
int a=Found_IT(arr,x,q);
if(a==0)
cout<<"element not found"<<endl;
else
{
cout<<p<<endl;
*p=-x;
cout<<"array elements are are as follows"<<endl;
for(i=0;i<20;i++)
cout<<arr[i];
}
return 0;
}
int Found_IT(signed long int arr[],signed long int x,signed long int **p)
{
for(int i=0;i<20;i++)
if(x==arr[i])
{
*p=&arr[i];
cout<<*p<<" "<<&arr[i]<<endl;
return 1;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.