c++ Program to search a number using Array
5:26 AM
use header files iostream.h and conio.h then
class array
{
public:
int arr[10];
void input()
{
cout<<"\n\nenter
the array Element";
for(int
i=0;i<=5;i++)
{
cin>>arr[i];
}
}
void search (int
no)
{
int
flag=0;
for
(int i=0;i<=5;i++)
{
if
(no==arr[i])
{
flag=1;
break;
}
}
if
(flag)
{
cout<<"element
is found";
}
else
{
cout<<"not
found";
}
}
};
void main ()
{
clrscr();
array a;
a.input();
int no;
cout<<"\nenter
the no to be search\n\n";
cin>>no;
a.search(no); //by
sourabh
getch();
}
Output:-
enter the array Element
1
2
3
5
9
4
enter the no to be search
5
element is found
0 comments