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

LINEARSE Search With Functions

This C++ code implements a linear search function to search for a target integer in an array of integers. The main function gets 10 integers from the user and stores them in an array. It then gets a search integer from the user and calls the search function, passing the array, search integer, and array size. The search function loops through the array, compares each element to the search integer, and if found prints the index+1 where found or prints "Not found" if not found after fully looping.

Uploaded by

Swapnil Gupta
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)
18 views

LINEARSE Search With Functions

This C++ code implements a linear search function to search for a target integer in an array of integers. The main function gets 10 integers from the user and stores them in an array. It then gets a search integer from the user and calls the search function, passing the array, search integer, and array size. The search function loops through the array, compares each element to the search integer, and if found prints the index+1 where found or prints "Not found" if not found after fully looping.

Uploaded by

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

Q 4. WAP to impliment linear search with functions .

#include<iostream.h>
#include<conio.h>
#include<process.h>
void search(int[],int,int);
void main()
{
clrscr();
int x[10],i,s;
cout<<"Enter 10 no: \n";
for(i=0;i<10;i++)
{
cin>>x[i];
}
cout<<"Enter search elements : \n";
cin>>s;
search(x,s,i);
getch();
}
void search(int num[],int s,int z)
{
for(int i=0;i<z;i++)
{
if(s==num[i])
{
cout<<" Found at : "<<i+1;
getch();
exit(1);
}
}
cout<<"Not found";
}

You might also like