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
________ ______ ________ ____ __________ ___ ______ ________.
____ ______ ____ ________ __________ __________ ______ ___ __________ ___ _____ _____.
_______ ___ ______ ________ _________ ___ _____ _______ ____.
__________ ___ ____ ________ __________ ___ _______ ___ _________ _______ ___.
___ ______ ___ _________ ___ ____ ________ ___.
______ ______ __________ _________ ______ _____.
_____ _____ _________ ________ ______ __________.
_____ ____ ______ __________ ________ _____ ____ _________.
______ ___ ____ __________ _____ __________ _______ __________ __________ ___ _________ _______.
_______ _____ ______ ___ ________ _______ _____.
___ ________ ____ ___ __________ ____ _____ ___ ______ __________.
_______ _________ ____ __________ ____ ________ ____ ________ _________ _____ _____ ______.
________ _________ __________ _____ __________ ___ ___.
_________ _________ __________ ____ _________ _________ _______ _____ ____ _________.
____ _________ ____ _________ _____ __________ ___ _____ __________ _____.
_________ _____ ____ _______ __________ ______ _____.
_______ __________ ________ ____ _____ ________ ____ ______.
___ _____ _______ _______ ____.
____ __________ ______ ________ ________ _____ __________ _________.
_____ ______ ________ _____ ______ ________ ___ _____ ___ _______.
______ ________ ___ _____ ______ ________ _________ ______.
______ ________ ________ ________ ________ ____.
_________ ____ __________ _________ __________ _____ ________ ____.
_______ ______ _______ _______ ________ _________ _________ _______ _______ _____ __________.
_____ ___ ___ ___ ____ _________ ________ ___.
___ ____ _________ _____ _________.
______ _________ ___ ________ ________ _________ _______ _______ _________ _____ ____.
___ ______ ______ _________ _______ __________ _________ _________ _______.
__________ ________ ___ ________ _________ ____ _____ __________ ______ _________ _______ _____.
_____ ____ _________ ________ ___ ___ ______ ________ _________ ________.
_____ _______ _____ ____ __________ ___ _______ ____ ________ _______ ____ _____.
____ __________ ________ __________ ___ __________ _____ __________ ________ _____ ________ _____.
______ ______ _____ __________ ________ __________ ___ ____ _______ _____ __________.
____ _______ _______ ________ _____ ________ _________ ______ _______ ____ ______ ____.
____ _________ __________ _______ __________ ______ ____ _______.
__________ _______ _______ ____ _________ ________ _________ ___ __________ _____ ___.
____ _____ ________ ________ _________ __________ ______ ____ ________ _______ _________ ___.
______ _________ ___ _______ ____ _____ ___ _____ _________ ______ _____ ____.
_________ ___ _________ __________ _____ _________ ________ __________.
_________ ____ ______ ____ ____.
___ ________ ______ _____ _______ _________ ______ __________ _______ _________.
_______ _____ _____ ______ ______ ___.
_________ ______ ____ ___ _______ _______ __________ ____ _____.
__________ _________ __________ ___ ___ _______.
_________ _______ ___ ______ ____ _____ ________.
_________ ________ _________ ________ _______ ___ ____ ______ _____ ____ ___.
________ __________ ________ ___ _________ ___ ___ _______.
_____ _________ __________ ________ _____ ________.
______ ______ _______ ___ _________ _____ ______.
_________ _____ ____ ______ _____ ___ __________ _______ _____.
_________ ___ _________ __________ __________ __________ _________.
________ _________ ______ ________ ________ _______ ________ ___.
___ ____ __________ _________ ________ _________ __________ _______ _____.
________ __________ ____ _______ __________ __________.
__________ _____ __________ __________ ______ ________.
_________ ____ ______ ____ _______ _________ _______ ________ _____ ___.
__________ _____ _______ _________ ________ _________ ________ ____ ________.
___ _______ ________ _________ ____ _________ ___ _________ __________ ___ __________ ________.
_______ ________ _____ ____ ________ ____.
_______ _________ _______ __________ __________ __________.
______ ___ _________ ____ _______.
___ _______ __________ ________ __________ _____ ________ _____ ___ _________.
____ ____ __________ ____ __________ ________ __________ __________ ______.
______ ___ ______ _______ _________ ______ __________ _____ _________ ________ ___.
_________ _____ _______ __________ ______ ________ ____.
_________ ________ ____ __________ ____ _________ ______ __________.
______ ____ ___ ________ _______.
_______ ____ ________ _____ __________ __________ _________ ______ _________ ____ _____.
_________ _________ ______ ____ ____ ____ _____ _________.
__________ ____ _______ _______ _______ ____ ________.
________ _____ _______ ________ ___ _______.
_____ ______ ________ __________ __________ _______ ________.
___ _______ __________ __________ ____ ________ ___ _______ ________ ______ _______.
__________ ____ ________ _________ _________ ______ ______ _____ ______ _______ __________ ____.
_________ _________ _________ _________ ___ ________.
______ ______ __________ _________ _______ __________ ________ _____ _____.
_______ _______ ________ _________ ____ ___.
_____ ______ ________ ______ ___ __________ _______ ____.
_______ ___ ___ ________ __________ _____ _______.
_________ ____ _________ _____ _________ __________ _____.
______ ____ __________ _____ ____ ____ __________ ______.
_________ ______ __________ ______ ________ __________.
____ ____ _______ ____ _________ ______ ____ _________ ___ _________.
_________ _________ _____ ___ ___ ______ _________ _______.
_________ ____ __________ _______ ___ _______.
____ _________ _______ ______ _____ _____ ____ _______ ______.
______ ____ ____ ________ ____ _________ ___ ____ ________ __________ __________.
____ ______ _________ ______ _____ ____ ____ _________ ______ __________ _____.
__________ _______ ____ ________ _________.
_______ ___ ________ _________ ________ ____.
______ ________ _____ ___ ____ _______ ____ _____.
_________ __________ ________ __________ _____ _______.
_________ _______ _______ ___ ___ ________.
____ ________ ______ _____ ________ ____ _________ _____.
_________ __________ ______ ___ _________ ________ __________ _______.
___ ____ _________ ______ ______ _______ _________ ______ ____ ____ ___ ___.
_________ _________ ___ _________ ________ _______ __________ __________.
________ _________ _____ ____ ________ ______ _______.
_______ _________ __________ ________ ____.
___ _______ ________ ____ _____ _______ ________ ______.
____ __________ ______ _______ ______ ________ _______ ______ ______.
_________ ___ _____ ________ ______ ______ ___ _______ _____.
___ ____ _____ ______ ____ _______.
____ __________ _______ ___ _________ ___ _____ _____ _______ _______ ________ _____.
____ _____ _____ ___ ________ __________ __________ _____ _______.
__________ _______ _______ ________ ____ __________ ____ _______ _______ ________ __________.
___ ____ _______ ___ ___ _________ _________ __________ ____ _____ ______ _________.
________ _________ ___ __________ ______.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU BCSL 45 2026 2027 -  Develop a C program to implement Linear Search and Binary Search | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→