Question

 Develop a C program to implement Linear Search and Binary Search.

07 Aug 2026
Answer :
Word Count : 1216
Linear Search and Binary Search are two important searching techniques used in algorithm design to find a particular element, called the key, from a collection of elements. Both methods have the same basic purpose, but they differ in their working procedure, requirements, and efficiency. Linear Search can be applied to both sorted and unsorted arrays, whereas Binary Search requires the array to be sorted. In Linear Search, the elements are examined one by one from the beginning of the array. The key is compared with each element until a match is found or the end of the array is reached. If the key is found, its position is returned. If the key does not exist in the array, an appropriate message is displayed. Linear Search is simple to implement and does not require the data to be sorted. The following C program implements both Linear Search and Binary Search: ```c #include int linearSearch(int arr[], int n, int key) { int i; for (i = 0; i < n; i++) { if (arr[i] == key) { return i; } } return -1; } int binarySearch(int arr[], int n, int key) { int low = 0; int high = n - 1; int mid; while (low <= high) { mid = low + (high - low) / 2; if (arr[mid] == key) { return mid; } else if (arr[mid] < key) { low = mid + 1; } else { high = mid - 1; } } return -1; } int main() { int arr[100]; int n; int i; int key; int choice; int result; printf("Enter the number of elements: "); scanf("%d", &n); printf("Enter %d elements in sorted order:\n", n); for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } printf("Enter the element to search: "); scanf("%d", &key); printf("\n1. Linear Search"); printf("\n2. Binary _________ ____ ______ _________ ___.
____ ____ ________ ______ ____ ______ _____ ___ _________ ____ ___ ____.
_____ _________ ____ ___ _____ _______ ______ __________.
________ _________ ____ ________ ____ ______ ____.
________ ______ ________ _______ ____ ______ __________ __________ __________ _______ ______.
_____ _______ ____ _____ _____ ________ _______ _________ ________ _____.
_____ _______ ________ _______ ____ __________ ________ ________ ______ __________.
______ ____ _____ ______ ____.
______ ___ __________ ___ _________ __________ _______ __________ ____ _________ _____.
_________ __________ _________ _______ _________ ______ ______ _______ __________.
___ ___ _________ _______ ________ ___ _____ _______ _______ ____.
_______ _____ ___ ___ _________ __________.
_______ ___ _______ ________ __________ _________ ________.
_____ ________ _____ ____ _________ _______ ____ ________ ____ _____ _________.
______ ____ ______ ______ ________ _________ ______ __________ ______.
______ _________ ___ ___ ________ ____ __________ ____.
_________ _______ ____ ____ _______ ___ _______ ______.
______ _______ ______ ______ _____ _________ _______ ________.
_______ ________ ____ ______ ________ __________ __________ ______ ________ _________.
________ _______ _______ _______ ____ ___.
_________ ___ ________ _______ ______ __________ ____ ____ __________ __________ ______ _________.
_________ ______ _____ ______ __________ _________ _______ _______ ________ _____ _______.
___ ________ _________ __________ ___ ______.
____ ___ __________ _________ _____ ________ ________ _______ ____ __________ _______.
____ ____ ______ ____ ____ ___ _______ ________ ______.
___ _______ ________ ____ _________ ______ _______ __________.
___ __________ ________ __________ ______ ____ _____ ___ _____.
____ ___ ____ ____ _________ _______ ____.
______ _________ _______ ______ ___ ____ ______.
____ __________ __________ _________ ______ ______ ______.
________ ______ _________ ______ _________ _____ ______.
______ _________ _____ ____ _________ _________ ______ _____ ________ _______.
_______ ____ ____ ________ ___ __________ ______ _______ _________ ______.
___ ___ ______ _______ _________ _______.
_______ _____ ___ ______ ______ __________ ______.
____ _________ ____ ___ _____ _____ ___ ________ ______ _____ _________.
_______ ____ _______ ____ ____ _________.
___ ____ ______ _______ _________ ___ _________ __________.
______ ____ ____ _________ ___ __________ ________.
_________ ____ _______ ____ _____ _______ ________ _______ ________ ___ _________ ____.
________ __________ _________ __________ ________ __________.
______ ______ _____ ________ ___ _________ ________ _______ ____ __________.
________ _______ ____ _______ _________ __________ ________ __________ ________.
______ ____ _______ ________ ________ ____ ____ __________ _____ __________ ___.
________ ______ _____ ____ _________ _________ _________ __________ __________ _____ ___.
____ _____ ________ _________ ____ _________ _____ ______ _____ ________ ________.
_________ ________ ____ _________ _________ ______ _________ _______ ____ __________ ____.
____ _______ _______ _______ ________.
_______ ________ ____ _______ _____ ___ _______ ______ _____ _____.
___ ________ ____ _______ ________ _____ __________ ______ ___ ____ ________ _____.
________ __________ __________ ___ __________ _________ _________ _________ ____ ________ _________ _________.
____ _________ _________ ______ _______ ________ ____.
__________ ___ _______ ____ ______.
__________ __________ _________ ____ ________.
___ ____ _____ ____ ___ __________ ________ ___ ___ _______.
________ _________ _________ _____ __________ __________.
_____ ____ ___ __________ ____ ____ ______ ________ ________ ______ _________ ___.
______ _________ _________ ________ __________ ___ ______ ___.
__________ ____ __________ _________ __________ ___ ______ _______ ______.
____ _____ __________ _________ ________.
___ _______ _______ _____ ___ _______ ______ ______ _________ ____ ____.
______ _________ _____ __________ ____ __________.
_____ _______ _________ ______ ______ _________ _______ ___ _____ ________ ____ _______.
_____ ___ ______ ________ _________ _________ _______ ____ ___ ______.
______ ____ ________ ____ ______ ________ ___ ________ ____ _________ ______.
___ ______ _________ ______ _______.
____ _______ _____ _____ ____ _________ __________ ______ _________.
_____ _______ ________ ___ ___ ___ ______ _______ ___ __________.
______ _____ _____ ________ ______ _________ _____ ___.
__________ ________ _________ __________ _________ _________ ____ _____.
___ _____ ______ _______ _________ __________.
__________ ______ ______ __________ ______ _______ ______ ___ ________.
_________ _____ ______ ____ _____ ____ ________ ________.
________ ___ _______ __________ ________ ________ __________ ________ ______.
_____ ____ ____ ______ _____ ________ __________ ___.
_____ __________ _______ ________ ______ ____ ________ _______.
____ _______ _________ ___ ____ ___.
___ _____ _____ _________ _____ ___ ___ _____ _____.
________ ____ ______ __________ ________ _________ ________.
______ ______ ____ _________ ______ ________ ______ _______ __________ __________ ___.
______ _______ ______ ________ ____.
____ ______ _____ _______ ______ __________ _______ ________.
______ ____ _____ __________ __________ ___ __________.
________ ______ ________ _______ ______ ______ _____ _____ ________ _________ _________.
____ _________ ______ ________ ______ _______ _____ _____.
________ ________ _____ ______ ____ __________ ________ _____ ________ ______.
_________ ________ _____ ______ __________ ______ ____ ___ ___ ____ _____ ____.
______ ______ ______ _____ _________ ________ ___ ______ ___ ________ ________.
______ _______ ______ ________ ___ ___ ___ ______ ______ _________.
______ _________ ____ _______ ____ ________ ____.
____ _________ ____ __________ _____ ___ ______ ___.
_______ __________ ________ ______ __________.
_________ _________ ____ __________ ______ _____ ________.
_______ _______ ____ ___ _____ ______ _________ _______ _____.
____ _________ ____ _________ _____.
_____ ______ _________ ___ __________ _____.
____ _________ _______ ________ _______ ___ _____ _________ ____ _____.
_________ _____ ___ ________ ___ _________ __________ __________ _____ _____ ____ ______.
________ ____ ________ _______ ____ ____ __________ _____.
_________ ________ ______ ______ __________.
_____ _____ _______ ________ _______ ______ ______ _______ _________ _______ ________.
_________ ____ _________ __________ _________ ____ ____ __________ ______.
__________ ________ ___ _____ ____ ___ _____ ________ __________ _______.
___ __________ _______ _______ ___ ______ _________ _______ _____.
_______ ____ __________ ____ ______ _____ _______ ___ ____ _________.
___ _____ ______ __________ ______ ____ __________.
____ ________ _________ ___.
Get Full Answer on WhatsApp
IGNOU NEWS
Assignment Submission Last Date Extended Till 30 June 2026 Click Here★★★IGNOU June 2026 TEE Date Sheet Released Click Here★★★
Top
📞
Call Support Instant phone assistance  Develop a C program to implement Linear Search and Binary Search
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→