n = atol( argv[1] );
if( n >= LONG_MAX )
{
printf( "given number is too large\n" );
return 2;
}
else if( i < n && n % i == 0 )
{
rc = 0;
}
else
{
i++;
while( i < n )
{
if( n % i == 0 )
{
rc = 0;
break;
}
i+=2;
}
}
if( !rc )
{
printf( "%ld is divisible by %ld.\n", n, i );
}
else
{
printf( "%ld can't be divisible by any prime number.\n", n );
}
return rc;
}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main(int argc, char *argv[])
{
long n = 0;
long i = 2;
int rc = 1;
if( argc < 2 )
{
printf( "usage: %s number\n", argv[0] );
return -1;
}
n = atol( argv[1] );
if( n >= LONG_MAX )
{
printf( "given number is too large\n" );
return 2;
}
else if( i < n && n % i == 0 )
{
rc = 0;
}
else
{
i++;
while( i < n )
{
if( n % i == 0 )
{
rc = 0;
break;
}
i+=2;
}
}
if( !rc )
{
printf( "%ld is divisible by %ld.\n", n, i );
}
else
{
printf( "%ld can't be divisible by any prime number.\n", n );
}
return rc;
}