Write a program that should consist of a user-defined
function “Task ()”. Pass 1D array to the function, along with
a number of elements of array and element to search. The function should implement a linear search. [Note: Array should be passed using by reference approach and Program is written in C language ]
Answers
I answered through image please mark as brainliest answer ♥️ please thank my answer please friend ❣️✌️❤️ God bless you
Answer:
#include<stdio.h>
int task(int*, int, int);
int main()
{
int array[100], search, c, n, position;
printf("Enter the number of elements in array\n");
scanf("%d",&n);
printf("Enter %d numbers\n", n);
for ( c = 0 ; c < n ; c++ ){
scanf("%d",&array[c]);
}
printf("Enter the number to search\n");
scanf("%d",&search);
position = task(array, n, search);
if ( position == -1 ){
printf("%d is not present in array.\n", search);
}
else{
printf("%d is present at location %d.\n", search, position+1);
}
return 0;
}
int task(int *pointer, int n, int find)
{
int c;
for ( c = 0 ; c < n ; c++ )
{
if ( *(pointer+c) == find ){
return c;
}
}
return -1;
}
Explanation: