Skip to main content

Program to Perform Linear Search on Array

· One min read
Kaustubh Kulkarni
Linear.cpp
#include<iostream>  
using namespace std;
int main()
{
int num,i,n,cnt=0,pos,c=0;
cout<<"Enter array size :";
cin>>n;
cout<<"Enter array elements :";
int arr[n];
for(i=0;i {
cin>>arr[i];
}
cout<<"Enter element to search :";
cin>>num;
for(i=0;i {
if(num==arr[i])
{
cout<<"Found at :"< c=1;
break;
}
else{
c=0;
}
}
if(c==0){
cout<<"Element not found!";
}
}