Find whether an element is present in an array or not.
Question: Write a program to find whether an element is present in an array or not?
Explanation:
A[10] = {10,20,30,40,50,60},ele = 60
We have to find whether element 60 is present in our array or not.
Programs:
#include<iostream>
using namespace std;
int main()
{
int A[10] = {10,20,30,40,50,60},pos,ele,flag=0;
cout<<"Enter an element to search:"<<endl;
cin>>ele;
for(int i=0;i<6;i++)
{
if(A[i] == ele)
{
flag = 1;
break;
}
}
if(flag==1)
{
cout<<"Element found";
}else{
cout<<"Element not found";
}
return 0;
}
0 Comment to "Find whether an element is present in an array or not."
Post a Comment
If you have any doubts then let me know.