Write a program to find the location of a given element using Linear Search

#include<iostream>
using namespace std;
int main()
{
int arr[10],n,i,o,e,count=0;
cout<<"Enter the no. of elements to be enter:";
cin>>n;
cout<<"Enter the elements:\n";
for(i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<"\nArray entered is :";
for(i=0;i<n;i++)
cout<<arr[i]<<" ";
cout<<"\nEnter the element to be Searched:";
       cin>>e;
       for(i=0;i<n;i++)
  {
       if(arr[i]==e)
       count++;
       }
       if(count==0)
       cout<<"\nElement not found";
       else if(count==1)
       cout<<"\nElement "<<e<<" exist "<<count<<" time in Array";
       else
       cout<<"\nElement "<<e<<" exist "<<count<<" times in Array";
       cout<<"\n/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}

Output:


Comments

Popular posts from this blog

To create an html page with frames and frameset

1. Write a program to insert a new element at end as well as at a given position in an array in Java

1. To familiarize with network devices like switch, hub, routers and bridges in LaTex