#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);
}