LinearSearch

This commit is contained in:
2021-04-27 13:49:55 +05:30
parent 6925ae0dca
commit c655dd624f
3 changed files with 30 additions and 1 deletions

28
LinearSearch.c Normal file
View File

@@ -0,0 +1,28 @@
// WAP to search an element in an array using Linear Sort.
void main() {
int a[10], i, item, n;
// To set range of array:
printf("\n Enter the range of array: \n");
scanf("%d", &n);
// To get values of array:
printf("\n Enter the elements of the array: \n");
for (i=0 ; i<=n; i++) {
scanf("%d", &a[i]);
}
// Liner Sort Algorithm:
printf("\n Enter item to search: \n");
scanf("%d", &item);
for (i=0; i<=n; i++) {
if (item==a[i]) {
printf("\n Item found at location %d", i+1);
break;
}
if (i>n) {
printf("\n Item does not exist.");
}
}
}

BIN
LinearSearch.exe Normal file

Binary file not shown.

View File

@@ -27,3 +27,4 @@
|25 | Array.c | Array.exe | WAP to print out an array of dynamic values |
|26 | ArrayReverse.c | ArrayReverse.exe | WAP to print out an array of dynamic values in reverse order |
|27 | BubbleSort.c | BubbleSort.exe | WAP to sort an array using bubble sort |
|28 | LinearSearch. | LinearSearch.exe | WAP to search an element in an array using Linear Sort |