diff --git a/searching/LinearSearch.c b/searching/LinearSearch.c index 23da2c8ff6..9fa9d89b61 100644 --- a/searching/LinearSearch.c +++ b/searching/LinearSearch.c @@ -1,27 +1,26 @@ #include -int linearsearch(int *arr, int size, int val){ - int i; - for (i = 0; i < size; i++){ - if (arr[i] == val) - return 1; - } - return 0; -} - -void main(){ - int s,i,v; - printf("Enter the size of the array:\n"); - scanf("%d",&s); +int main() +{ + int arr[6]={5,9,12,3,36,28}; + printf("\nEnter the key to search : "); + int num,x,found; + scanf("%d",&num); + for(x=0;x<6;x++) + { + if(num ==arr[x] ) + { + printf("\nkey has found in %d index",x); + found=1; + break; + } + else{continue;} - int a[s]; - printf("Enter the contents for an array of size %d:\n", s); - for (i = 0; i < s; i++) scanf("%d", &a[i]); + } - printf("Enter the value to be searched:\n"); - scanf("%d", &v); - if (linearsearch(a, s, v)) - printf("Value %d is in the array.\n", v); - else - printf("Value %d is not in the array.\n", v); + if(found!=1) + { + printf("Search not found!"); + } + return 0; }