Name: Get the factor!
By: Vinicius Josh Fortuna
Description: This program shows the factors of a number and tests whether it is a prime number or not.
Below is the screenshot of the program. One of the example that I entered is number 888, then, the factor of this number is 2*2*2*3*37. I also entered the number 2 and 5 which displayed a prime number and can't be factor out.
//Below are the Codes of the Program:
#include <stdio.h>
#include <math.h>
int main()
{
int number; /* The number read */
int gpf; /* Greatest possible factor */
int factor;
enum { FALSE, TRUE } isPrime;
do
{
printf("Enter the number to be factor or 0 to end: ");
scanf("%d", &number);
if(number!=0)
{
isPrime = TRUE;
gpf = floor(sqrt(number));
for(factor=2; factor <= gpf; factor++)
while(number%factor==0 && number!=1)
{
if(isPrime)
{
printf("%d = %d", number, factor);
isPrime = FALSE;
}
else
printf(" * %d", factor);
number = number/factor;
}
if(isPrime)
printf("%d is a prime number.", number);
else if(number!=1)
printf(" * %d", number);
printf("\n\n");
}
}while(number!=0);
return 0;
}