Created
November 15, 2021 19:05
-
-
Save jkoop/7e8caab11918b9b17d73e9a2fe29fba3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> // gcc -lm enumerateFactorsOfN.c | |
int enumerateFactorsOfN(int n) { | |
int factors = 1; | |
double sqrtN = sqrt(n); | |
int n2 = (int) sqrtN; | |
for (int i = 1; i <= n2; i++) { | |
if (n % i == 0) { | |
factors++; | |
} | |
} | |
factors *= 2; | |
if (sqrtN == n2) { | |
factors--; | |
} | |
return factors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment