Answers for "c++ find number of divisors"

C++
0

c++ find number of divisors

// https://www.geeksforgeeks.org/count-divisors-n-on13/
int countDivisors(int n) { 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
}
Posted by: Guest on July-07-2020

Code answers related to "c++ find number of divisors"

Browse Popular Code Answers by Language