LINEAR SEARCH OPERATION IN C LANGUAGE
#include<stdio.h>
int linear(int arr[],int size,int element){
for(int i=0;i<size;i++){
if(arr[i]==element){
return i+1;
}
}
return -1;
}
int main()
{ int size,arr[size],element;
printf("please enter the size of array\n");
scanf("%d",&size);
printf("enter the elements for the array \n");
for(int i=0;i<size;i++){
scanf("%d",&arr[i]);
}
printf("enter the elment to be searched \n");
scanf("%d",&element);
int index = linear(arr,size,element);
printf("the element %d is found at %d position \n",element,index);
return 0;
}
0 Comments