//Searching a Number in a given array values
#include < iomanip >
#include < iostream >
using namespace std;
void main()
{
short *arr,*end,size,*ptr,temp,sv;
cout << "Enter size of the array" << endl;
cin>>size;
ptr=arr=new short[size];
end=arr+size-1;
cout << " Enter " << size << " values" << endl;
while(ptr <= end)
{
cin>>*ptr++;
}
cout << endl << "Enter a number to search:: ";
cin>>sv;
ptr=arr;
temp=*end;
*end=sv;
while(sv!=*ptr)
{
ptr++;
}
if(end==ptr)
{
if(temp==sv)
cout << "FOUND at Subscript " << ptr-arr << endl;
else
cout << "NOT FOUND" << endl;
}
else
cout << "FOUND at line " << ptr-arr+1 << endl;
system("pause");
}
Subscribe to:
Post Comments (Atom)
Comments (0)
Post a Comment