Skip to main content
Search
Search This Blog
Livecodo
Pages
Home
Courses
Blog
About us
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
May 02, 2024
Write a c program to perform linear Search
#include
int linearSearch(int arr[], int n, int x) { for (int i = 0; i < n; i++) { if (arr[i] == x) { return i; } } return-1; } int main() { int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr) / sizeof(arr[0]); int x; printf("Enter the element to search: "); scanf("%d", &x); int result = linearSearch(arr, n, x); if (result ==-1) { printf("Element is not present in array\n"); } else { printf("Element is present at index %d\n", result); } return 0; }
Popular Posts
March 26, 2024
Dynamic Memory allocation in C
May 18, 2024
Searching and sorting Algorithm in C