C++ PROGRAM int find int item, const int array[], int elements elements is the n
ID: 3768960 • Letter: C
Question
C++ PROGRAM
int find int item, const int array[], int elements elements is the number of elements in the array The function's job is to locate the position of the first occurrence of item's value in the array. For example, if array held 12, 4, 6, 8, 10, 8, 6,4, 2), then find 8, array, 9 would return 3, because the first 8 occurs in array[3]. If item is not in the array, the function should return INT MAX int howMany int item, const int array[], int elements Same args as the last function. This function's job is to return the number of times the value of item appears in the array For example, if array held 12, 4, 6, 8, 10, 8, 6, 4,2, then how Many 8, array, 9) would return 2, because there are 28's in the array.Explanation / Answer
int find(int item, const int array[], int elements)
{
int i,a;
for(i=0;i<elements;i++)
{
if(array[i]==item)
{
a=i;
}
}
return a;
}
int howMany(int item, const int array[], int elements)
{
int i,a=0;
for(i=0;i<elements;i++)
{
if(array[i]==item)
{
a++;
}
}
return a;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.