# Thread: How do I do a program with factors?

1. ## How do I do a program with factors?

Im doing a program that has to ask the user for two positive integers and outputs. I need it to have the inputs, all the factors of each (include 1 and itself), the prime factorization of each, the least common multiple (LCM) of the two integers, and the greatest common factor (GCF) of the two integers. I already started but Im having problems starting the factors. I have no idea how to do it. Do I have to go through each and every single number to check the input numbers or what? Im totally confused. I hope theres someone here who can help me out with this little problem. Thanks

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

void main(void)

{
int num1;
int num2;

printf("Please enter two positive numbers: \n");
scanf("%d%d%", &num1, &num2);

if ((num1 < 0) || (num2 < 0))
{
}
else
{

}
}```

2. You don't nessicarily need the numbers to be positive. In order to do the prime factorization of a negative number is to factor in a
-1. I am not sure how to do all those other things though, but to find the GCF of the two numbers, you have to get the prime factorization and then find matching terms in different numbers and multiply different matching terms. EX:

30: 1 * 2 * 3 * 5
12: 1 * 2 * 2 * 3

One pair of three's and two's match to you multiply three and two and you get 6 the GCF of 30 and 12. Hope this helps you!

3. Here is *the algorithm* for finding GCF of 2 numbers...

Code:
```int GCF (int i1, int i2)
{
int i3;
for (;;)
{
i3 = difference between i1 and i2;
if (i3 == 0) break;
bigger of i1 and i2 = i3;
}
return i1;
}```
Let's run through this code...
Code:
```i1: 27 27 18  9
i2: 36  9  9  9
i3:  9 18  9  0  ...  return 9;```
Code:
```i1: 96 69 42 15 15  3  3  3  3
i2: 27 27 27 27 12 12  9  6  3
i3: 69 42 15 12  3  9  6  3  0  ... return 3;```
There are quicker ways to check when to terminate the loop, but this one does work.

Once you have the GCF of two numbers, finding the LCM is pretty simple...
LCM (a, b) = a * b / GCF (a, b)

4. You mean a ; ), not a , don't you?

(Check the "disable smilies" box or put a space between the ';' and the ')')

Just thought I'd point this out