IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
Earn Free Bitcoin
CAdvanced Functions ❯ List of Divisors
<06.04>
#include <stdio.h> #include <math.h> // returns true if n is even // returns false if n is odd int even (int n) { return (!(n%2)); } //function returns the divisor int find_div (int n) { int divisor, i; // looking for a divisor. if found, it // is not a prime number divisor = 0; // eliminating even numbers except 2 if (even (n)) { if (n==2) divisor=0; else divisor=2; } else { if (n==1) divisor=0; // 1 is a prime number else // trying to divide number by 3,5,7,... // to find a divisor until sqrt(n) for (i=3; i<=sqrt(n); i=i+2) { if (!(n%i)) divisor=i; } } // if there is a divisor then NOT prime return (divisor); } int main (void) { int x; for (x = 1; x <= 50; ++x) if (find_div (x) != 0) printf ("%3d > %2d\n", x, find_div(x)); else printf ("%3d*\n", x); return (0); }
Hergestellt in Deutschland / Made in Germany
1* 2* 3* 4 > 2 5* 6 > 2 7* 8 > 2 9 > 3 10 > 2 11* 12 > 2 13* 14 > 2 15 > 3 16 > 2 17* 18 > 2 19* 20 > 2 21 > 3 22 > 2 23* 24 > 2 25 > 5 26 > 2 27 > 3 28 > 2 29* 30 > 2 31* 32 > 2 33 > 3 34 > 2 35 > 5 36 > 2 37* 38 > 2 39 > 3 40 > 2 41* 42 > 2 43* 44 > 2 45 > 5 46 > 2 47* 48 > 2 49 > 7 50 > 2
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.