The list of random numbers stored in an integer and float array. Perform search operation to find the search number is present or not from an array using templates concept.
* Print - Element Found or Element Not Found
#include <iostream>
using namespace std;
int main()
{
int a[10];
float b[10],n;
srand(time(0));
for (int i = 0; i < 10; i++)
a[i] = 1 + rand() % 5;
for (int i = 0; i < 10; i++)
b[i] = 1 + (rand() % 5)/10;
cout << "Enter num: "<< endl;
cin>>n;
int count=0;
for (int i=0; i<10; ++i)
if (a[i]==n|| b[i]==n)
count++;
if (count==0)
cout<<"Element Not Found";
else
cout <<"Element Found";
return 0;
}
Comments
Leave a comment