I've been working on a program and have hit a roadblock. I know conceptually what to do, but I'm having trouble implimenting it.
Ok, so what it's suppose to do is take them randomly generated numbers that have been put in arrayints and factor them. This right now for an example if the number is 100 it will print out: 2 * 50 4 * 25 5 * 20 10 * 10 1 * 100. What I want it to print out is: 2 * 2 * 5 * 5 (doesn't have to be in that order I guess) but I'm having trouble with this. It's probably something simple that I'm overlooking but if anybody could help with it that would be great. Thanks!
Conceptually, I know I need to take the number I get from the if((arrayints % j) == 0 && arrayints != j) and run it back through here. Ex. 100, you would get factor1 = 2, and factor2 = 50, so I need to somehow run factor2 back through the if statement without incrementing j. (hopefully you understand what I mean lol)
for (int i = 0; i < integerIn; i++)
{
cout << "The factors for " << arrayints[i] << " are: ";
for (int j = 2; j <= floor (sqrt((double)integerIn)); j++)
{
if ((arrayints[i] % j) == 0 && arrayints[i] != j)
{
factor1 = j;
factor2 = arrayints[i]/j;
cout << factor1 << " * " << factor2 << " ";
}
}
factor1 = 1;
factor2 = arrayints[i];
cout << factor1 << " * " << factor2 <<endl;
}