Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- int linearsearch(int a[], int key)
- {
- int i, location = -1;
- for (i = 0; i < 10 ; i++)
- {
- if (a[i] == key)
- {
- location = i + 1;
- return location;
- }
- }
- return location;
- }
- int main()
- {
- int key, loc;
- int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- printf("Enter the Key: ");
- scanf("%d", &key);
- loc = linearsearch (a, key);
- if (loc == -1)
- {
- printf("Search Unsuccessful. Input a correct key.\n");
- }
- else
- {
- printf("The location of Key %d is %d", key, loc);
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement