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

Program to illustrate the concept of templates.

To create an html file to implement the concept of margin, padding using cascading style sheets.

To configure the IP address for a computer connected to LAN