Write a program Of searching of the array element METHOD 2

//this is a program Of searching of the array element METHOD 2
#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
int a[5],flag=0,i,search;


//Accepting the array elements

cout<<"\n\n\tEnter the elements of the array: ";
for(i=0;i<5;i++)
{
cout<<"\n\tEnter the element: ";
cin>>a[i];
}

//Displaying the array elements
cout<<"\n\n\tDisplaying the array elements: \n\t";
for(i=0;i<5;i++)
cout<<" "<<a[i];

//Accepting the array element to be found

cout<<"\n\n\tEnter the element you want to find: ";
cin>>search;

//Searching the element

for(i=0;i<5;i++)
{
if(a[i]==search)
{
flag=1;
break;
}
}

if(flag==0)
cout<<"\n\n\tElement not found.";
else
cout<<"\n\n\tElement Found.";

return 0;



}

Previous
Next Post »