Computer Science, asked by brilliantpride123, 4 days ago

write a C program ,function for search, which accepts an array of n elements and a key as parameters and return the position of key in the array and -1 if the key is not found. accept'n' numbers from user, store them in an array. accept the key to be searched and search it using this function.​

Answers

Answered by rajputghanendra195
0

Answer:

C programming language by At & T,s Bell laboratories of USA in 1972

Answered by samarthkrv
1

Answer:

#include <stdio.h>

int search(int arr[] , int len , int key);

int search(int arr[] , int len , int key){

   for(int i = 0; i < len; i++){

       if(arr[i] == key){

           return i;

       }

   }

   return -1;

}

int main()

{

int arr[10];

printf("Enter all the 10 elements of the array- \n");

int len = sizeof(arr) / sizeof(arr[0]);

   for(int i = 0; i < len; i++){

       scanf("%d" , &arr[i]);

   }

   int n;

   printf("Enter a number you want to search in the array:");

   scanf("%d" , &n);

   printf("%d" , search(arr , len , n));

}

Explanation:

Similar questions