
#include <iostream>

int IsComposite(int i);

int main(void )
{
  int i;

  std::cout << "Enter a natural number: ";
  std::cin >> i;

  if (IsComposite(i))
    std::cout << i << " is a composite number." << std::endl;
  else
    std::cout << i << " is a prime number." << std::endl;

  return(0);
}

// Check if i as a Composite number (i.e., not prime)
// Return its smallest divisors if it is composite.
// Return 0 if it is prime,
int IsComposite(int i)
{
  int k;

  for (k=2; k<i; k++)
    if ( (i%k) == 0)
      return(k);

  // If we get to here, then i has no divisors between 2 and i-1
  return(0);
}



