//search element using pointer
#include<iostream>
using namespace std;
int main()
{
int i,a[10],b,*p1,*p2;
cout<<"enter 10 no.\n";
p1=a;
for(i=0;i<10;i++)
{
cin>>*(p1+i);
}
cout<<"enter searching element\n";
cin>>b;
p2=&b;
for(i=0;i<10;i++)
{
if(*(p1+i)==*p2)
cout<<"element found";
}
}
#include<iostream>
using namespace std;
int main()
{
int i,a[10],b,*p1,*p2;
cout<<"enter 10 no.\n";
p1=a;
for(i=0;i<10;i++)
{
cin>>*(p1+i);
}
cout<<"enter searching element\n";
cin>>b;
p2=&b;
for(i=0;i<10;i++)
{
if(*(p1+i)==*p2)
cout<<"element found";
}
}
No comments:
Post a Comment