// divisors.c -- nested ifs display divisors of a number
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
	// number to be checked
	long num;
	// potential divisors
	long div;
	// prime flag
	bool numIsPrime;

	printf("Please enter an integer for analysis; "
		"Enter q to quit.\n");
	while (scanf("%ld", &num) == 1)
	{
		for (div = 2, numIsPrime = true; (div * div) <= num; div++)
		{
			if (num % div == 0)
			{
				if ((div * div) != num)
				{
					printf("%ld is divisible be %ld and %ld.\n",
						num, div, num / div);
				} else {
					printf("%ld is divisible by %ld.\n", num, div);
				}
				// number is not prime
				numIsPrime = false;
			}
		}
		if (numIsPrime)
		{
			printf("%ld is prime.\n", num);
		}
		printf("Please enter another integer for analysis; "
			"Enter q to quit.\n");
	}
	return 0;
}