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 implement the various components of HTML5 Canvas

Program to illustrate the concept of templates.

Program to illustrate the order of execution of constructors and destructors in inheritance.