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
26 changes: 26 additions & 0 deletions Searching/Linear search
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>

int main()
{
int arr[100],n,i,data,flag=0;//flag is used when the data does not mathces with any of the array element
printf("Enter the size of array: ");
scanf("%d",&n);
printf("Enter the elements in array: ");
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
printf("Enter the element you want to search: ");
scanf("%d",&data);
for(i=0;i<n;i++){
if(data==arr[i]){
printf("Element is present at index: %d",i);
flag=1;
break;
}
}
if(flag==0){
printf("Element not found.");
}
return 0;

}