#include <iostream>
using namespace std;
template <class t1>
int search(t1 arr[], int size, t1 n)
{
for (int i = 0; i < size; i++)
{
if (arr[i] == n)
{
return i;
}
}
return -1;
}
int main()
{
float arr[] = {1, 2, 3};
int size = (sizeof(arr) / sizeof(arr[0]));
cout<<"enter element to be searched\n";
float m;
cin>>m;
int n = search<float>(arr, size, m);
if (n==-1)
{
cout<<"not found\n";
}
else
cout<<"found at index "<<n<<endl;
}
No comments:
Post a Comment