Anti-primes: Difference between revisions
Content added Content deleted
(Added Go) |
(Added C) |
||
Line 10: | Line 10: | ||
;Related task: |
;Related task: |
||
::* [[Factors of an integer]] |
::* [[Factors of an integer]] |
||
=={{header|C}}== |
|||
{{trans|Go}} |
|||
<lang c>#include <stdio.h> |
|||
int countDivisors(int n) { |
|||
int i, count; |
|||
if (n < 2) return 1; |
|||
count = 2; // 1 and n |
|||
for (i = 2; i <= n/2; ++i) { |
|||
if (n%i == 0) ++count; |
|||
} |
|||
return count; |
|||
} |
|||
int main() { |
|||
int n, d, maxDiv = 0, count = 0; |
|||
printf("The first 20 anti-primes are:\n"); |
|||
for (n = 1; count < 20; ++n) { |
|||
d = countDivisors(n); |
|||
if (d > maxDiv) { |
|||
printf("%d ", n); |
|||
maxDiv = d; |
|||
count++; |
|||
} |
|||
} |
|||
printf("\n"); |
|||
return 0; |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
The first 20 anti-primes are: |
|||
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |