Count the factors of K present in the given Array | C ++ implementation to find the count of factors of K present in array ; Function to find the count of factors of K present in array ; Loop to consider every element of array ; Driver Code ; Function Call
#include <iostream> NEW_LINE using namespace std ; int calcCount ( int arr [ ] , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( k % arr [ i ] == 0 ) count ++ ; } return count ; } int main ( ) { int arr [ ] = { 1 , 2 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 6 ; cout << calcCount ( arr , n , k ) ; return 0 ; }