# countif

Calculates the number of elements in an array that satisfy a certain condition.

## Dependents

## Interface

C++

## Overview

The components available with this module calculate the number of elements in an array that satisfy a certain condition. The difference between the two functions consists in the way the condition is given.## Countif

template<class T> intcountif( | int | n | |

T* | data | ||

T | cmp | ||

bool | (*fctpnt)(const T&, const T&)[function pointer] | ) |

## Example:

#include <iostream> #include <codecogs/stats/countif.h> int main() { int x[12] = {3, 5, 1, 2, 6, 8, 10, 2, 2}; std::cout << "The number of elements equal to 2 is: "; std:: cout << Stats::countif<int>(12, x, 2, Stats::isEqual); std::cout << std::endl; std::cout << "The number of elements greater than 3 is: "; std::cout << Stats::countif<int>(12, x, 3, Stats::isGreater); std::cout << std::endl; std::cout << "The number of elements less than 7 is: "; std::cout << Stats::countif<int>(12, x, 7, Stats::isLess); std::cout << std::endl; return 0; }

## Output:

The number of elements equal to 2 is: 3 The number of elements greater than 3 is: 4 The number of elements less than 7 is: 10

### Authors

*Lucian Bentea (September 2005)*

##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.

## Countif

intcountif( | int | n | |

int* | data | ||

const char* | cmp | ) |

## Example:

#include <iostream> #include <codecogs/stats/countif.h> int main() { int x[12] = {3, 5, 1, 2, 6, 8, 10, 2, 2}; std::cout << "The number of elements equal to 2 is: "; std::cout << Stats::countif(12, x, "=2"); std::cout << std::endl; std::cout << "The number of elements greater than 3 is: "; std::cout << Stats::countif(12, x, ">3"); std::cout << std::endl; std::cout << "The number of elements less than 7 is: "; std::cout << Stats::countif(12, x, "<7"); std::cout << std::endl; return 0; }

## Output:

The number of elements equal to 2 is: 3 The number of elements greater than 3 is: 4 The number of elements less than 7 is: 10

### Parameters

cmp Constant

##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.