#include <iostream>
template<class T>
int count(T arr[], int n,const T &value) // use const in case accidentlly modified
{
int countValue = 0;
for (int i = 0; i < n; i++)
{
if (arr[i] == value)
countValue++;
}
return countValue;
}
int main()
{
double arr[100];
// assign value
double value = 45.5;
for (int i = 0; i < 100; i++)
{
if (i % 2 == 0)// even number
arr[i] = value;
else
arr[i] = 0.01;
}
std::cout << "In array arr[100], there are " << count<double>(arr, 100, value) << " elements equals 45.5.\n";
system("pause");
return 0;
}
06-16
08-26