0% found this document useful (0 votes)
28 views

Program To Search A Given Value in List Using Linear Searching Method

This program uses linear search to find a given value in a list. It takes user input for the number of elements and values to store in an array. It then takes a search value from the user and calls the linear search function, passing the array, size, and search value. The linear search function loops through the array, compares each element to the search value, and returns the index position if found or -1 if not found.

Uploaded by

jayesh_meena
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Program To Search A Given Value in List Using Linear Searching Method

This program uses linear search to find a given value in a list. It takes user input for the number of elements and values to store in an array. It then takes a search value from the user and calls the linear search function, passing the array, size, and search value. The linear search function loops through the array, compares each element to the search value, and returns the index position if found or -1 if not found.

Uploaded by

jayesh_meena
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PROGRAM TO SEARCH A GIVEN VALUE IN LIST USING LINEAR SEARCHING METHOD

#include<iostream.h> #include<conio.h> int lsear(int [],int void main() { clrscr(); int ar[20],n,it,k,i,index; cout<<"enter no of ele. in the array"; cin>>n; cout<<"enter array ele."; for(i=0;i<n;i++) { cin>>ar[i]; } cout<<"enter the no. of to b search"; cin>>it; cout<<"the it is at position"; index=lsear(ar,n,it); cout<<"te no is at pos "<<index; getch(); } int lsear(int ar[],int n,int it) { int i; for(i=0;i<n;i++) { if(it==ar[i]) return i+1; } ,int ) ;

return -1; }

You might also like