Wednesday, 4 May 2016

Searching element in array using pointers

#include<iostream.h>
#include<conio.h>
void main()
{
int a[5],*p,no,flag=0,i;
clrscr();
p=&a[0];
cout<<"Enter Elements:";
for(i=0;i<5;i++)
{
cin>>*p;
p++;
}
p=&a[0];
cout<<"Enter no to be searched:";
cin>>no;
for(i=0;i<5;i++)
{
if(*p==no)
{
cout<<"No is present";
flag=0;
break;
}
else
{
flag=1;
}
p++;
}
if(flag==1)
{
cout<<"No not present";
}
getch();
}


No comments:

Post a Comment