A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

wap TO SEARCH AN ELEMENT in 1 d array(linear searching).

//program to search an element in 1 d array

//here p=position

#include<iostream>
using namespace std;
int main()
{

int a[10],size,i,f,num,p;

cout<<"\n Enter the element in the array:";
cin>>size;

cout<<"\n enter the element in assending array";

for(i=0;i<size;i++)
cin>>a[i];
cout<<"\n enetr the element for search";
cin>>num;

for(i=0;i<size;i++)
if(a[i]==num)
{
f=1;
p=i;
break;
}
if(f==0)
cout<<"\n no any element";
else
cout<<"\n element position is"<<p;
}

LEARN TUTORIALS

.

.