#include stdio
/* PRIME NUMBER PROBLEM
How can you tell whether a number is prime or not? Pretty simple. Divide it by 2, 3 ... and if it is divisible by any, it is composite. That is what mathematicians calls numbers that are not prime). Of course, after you have tested it for divisibilty by 2, you need only odd numbers for division. And what is the largest divisor you need try before you can conclude that the given number was a prime? If a number is composite, it has one divisor not greater than its square root : so after having verified that the given number is not even ( because if it is even, it is certainly composite, unless it is 2 ) we need merely use the series of divisors 3, 5, 7, .... (int)square_root(n) to determine if it is prime. The program below does just that :
*/
main( )
{
int number, factor;

scanf("%d", &number);

{
if (number = = 2 | | number = = 3)
{
printf("%d is a prime .......\n", number);
exit(0);
}
else
if ( number % 2 = = 0)
{
printf("%d is composite .......\n", number);
exit(0);
}
for ( factor = 3 ; ; factor + =2 )
if (number % factor = = 0)
{
printf( "%d is composite ..... \n", number);
break;
}
else
if ( factor * factor > number )
{
printf("%d is a prime ....\n", number);
break;
}
}
}