AIM : Linear Searching
#include <stdio.h>
int main()
int arr[5] = {10, 25, 30, 45, 50};
int i, key, found = 0;
printf("Enter the element to search: ");
scanf("%d", &key);
for(i = 0; i < 5; i++)
if(arr[i] == key)
printf("Element %d found at position %d\n", key, i + 1);
found = 1;
break;
if(found == 0)
printf("Element %d not found in the array\n", key);
return 0;
OUTPUT :
AIM: Binary Searching
#include <stdio.h>
int main() {
int arr[100], n, i, key;
int low, high, mid, found = 0;
printf("Enter 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 element to search: ");
scanf("%d", &key);
low = 0;
high = n - 1;
while(low <= high) {
mid = (low + high) / 2;
if(arr[mid] == key) {
found = 1;
break;
else if(arr[mid] < key) {
low = mid + 1;
else {
high = mid - 1;
}
if(found == 1)
printf("Element found at position %d\n", mid + 1);
else
printf("Element not found\n");
return 0;
OUTPUT: