LinearSearch
This commit is contained in:
28
LinearSearch.c
Normal file
28
LinearSearch.c
Normal 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
BIN
LinearSearch.exe
Normal file
Binary file not shown.
@@ -27,3 +27,4 @@
|
|||||||
|25 | Array.c | Array.exe | WAP to print out an array of dynamic values |
|
|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 |
|
|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 |
|
|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 |
|
||||||
Reference in New Issue
Block a user