# include <iostream.h>
# include<conio.h>
int search(int[], int);
void main( )
{
int arr[10], num, i, subscript;
cout<<"\n Input 5 array elements : ";
for(i=0;i<5;i++)
cin>>arr[i];
cout<<"\n Enter number to be searched :";
cin>>num;
if((subscript = search(arr,num)) == -1)
cout<<"\n No such element !! ";
else
cout<<"\n Element found at : "<<subscript;
getch( );
}
int search(int arr[], int num)
{
int i ;
for(i=0; i<5; i++)
{
if (arr[i] == num)
return i +1;
}
return -1;
}
0 comments:
Post a Comment