Write a function name ‘findNumber’ that will receive three parameters: the first one is an int one-dimensional array ‘arr’, the second one is an integer ‘n’ that represents the number of elements in the array and the third one is an integer ‘x’. Using POINTERS search the array ‘arr’ for the first occurrence of that number ‘x’. If you find the number, return the position of the number in the array; otherwise return -1.
For example if the array contains the numbers: 10, 20, 60, 5, 60 and you search for the number 60, then the function should return 2.
ANSWER:
#include <stdio.h>
int findNumber(int arr[],int n,int x)
{
int *ptr=arr; //pointer pointing to 1st element of array
int i=0;
for(i=0;i<n;i++)
{
if(*ptr==x) //if ptr pointing value is x return position
{
return i;
}
ptr++; //increment ptr to point to next value in array
}
return -1; //if number doesnt match to any value in array returning
-1
}
int main()
{
int n,x;
printf("Enter number of elements in array:"); //n value from
keyboard
scanf("%d",&n);
int arr[n];
printf("Enter elements into array:");
for(int i=0;i<n;i++)
{
scanf("%d",&arr[i]); //array values from keyboard
}
printf("Enter element to search:");
scanf("%d",&x); //x value from keyboard
int pos=findNumber(arr,n,x); //function call
printf("position=%d",pos);
return 0;
}
//if any doubt please verify below pic


OUTPUT:
//if element in array

//if element not in array

Write a function name ‘findNumber’ that will receive three parameters: the first one is an int...
Write a function template named summarray, with two parameters: and array called are and an int holding the number of elements in arr. The function should return the sum of the elements in arr. this template must work for double or int arrays. Show a sample function call to the template function you wrote. What would you have to do to use the templates sumArray function with an array of objects of a custom class?
A function that takes three parameters: an int array, an int n that is the size of the array and an int pointer max that is to assign the maximum value in the array. The function will find and return the index of the first occurrence of the maximum value in the array and assign the maximum value to the pointer. For example, in the array {1, 2, 6, 5, 6, 4, 3, 6, 4}, the maximum value is 6...
The function takes three parameters: string array, int arraySize, and string word The function will loop through the string array. If word is found in the array, return the matched element’s position (index) in the array. Otherwise, return -1. When a match is found in the array, the loop should be terminated at the time --- no need to continue the loop. If no match is found, the function should display all elements in the array, as well as the...
Write a function with two input parameters: an array of numbers and the size of the array (the number of elements). The function should return the count of even numbers in the array. For example, if the input to the function is the array [3, 2, 45, 56, 12], the function would return the integer 3. Use the following function header: int countEvens(int nums[], int size) { }
A method called linearSearch(), which takes as parameters an array of int followed by three values of type int, and returns a value of type int. The first int parameter represents a key, the second int parameter represents a starting position, and the third int parameter represents an end position. If the key occurs in the array between the start position (inclusive) and the end position (exclusive), the method returns the position of the first occurrence of the key in...
Write a C++ function, smallestIndex, that takes as parameters an
int array and its size and returns the index of the first
occurrence of the smallest element in the array. To test your
function, write a main that prompts a user for a list of 15
integers and outputs the index and value of the first occurrence of
the smallest value.
The program should print out
Enter 15 integers:
The position of the first occurrence of the smallest element in...
(C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...
must be done in C
You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int size, int arr]); The first parameter is the number of elements in the array. The second parameter is an address to the beginning of an int array. In the body of the function, use a looping structure to identify and return the maximum (largest number) of the array. NOTE: The maximum of the same number, say...
write a C program!! Q2 and Q3
Write the following functioned int search(int a[], int n, int key, int **loc); a is an array to be searched, n is the number of elements in the array, key is the search key, and loc is a pointer to the first location of the search key in array a (if found) or NULL otherwise. The function returns 1 if key is found in a, and returns 0 otherwise. Write a main() and...
13. Write a recursive function with the declaration: int count Equal (int* numbers, int n, int x) that has as parameters an array numbers with n > 0 elements, and an integer x, and returns how many times I appears in the array. 14. Write a recursive function with the declaration: double dist(double* u, double *v, int n) that gets two double precision arrays with n > 1 elements and returns the value: Vu[0] - v[0])2 + (u[1] – v[1])2...