Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions searching/LinearSearch.c
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
#include <stdio.h>

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;
}