# Count STL Algorithm

## Count STL Algorithm

The count() algorithm returns the number of elements in the sequence beginning at start and ending at end that match val.

```
template&lt; class InputIterator, class T &gt;
typename iterator_traits&lt;InputIterator&gt;::difference_type
count( InputIterator first, InputIterator last, const T &amp;value );

Count appearances of value in range (function template)
Returns the number of elements in a range whose values match a specified value.
Returns the number of elements in the range [first, last) matching given value value.

```

### Implementation of count() algorithm

```
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

typedef int type;
const int size=10;

int main ()
{
type const list[size]= {1,3,5,9,2,6,7,2,9,0};
vector&lt;type&gt; vec0(list, list+10);
type result;

for ( int k=0; k&lt; vec0.size(); k++ )
{
result = count(vec0.begin(), vec0.end(), vec0[k]);
cout &lt;&lt; &quot;number: &quot; &lt;&lt; vec0[k] &lt;&lt; &quot; count: &quot; &lt;&lt; result &lt;&lt; endl;
}

return 0;
}// end of main
```

Program Output:

```
number: 1 count: 1
number: 3 count: 1
number: 5 count: 1
number: 9 count: 2
number: 2 count: 2
number: 6 count: 1
number: 7 count: 1
number: 2 count: 2
number: 9 count: 2
number: 0 count: 1

```