This problem asks me to find the factors of a user inputted number and then to find out if it is prime from how many factors are outputted but i can't figure out how to count the number of factors. Any help would be appreciated. Here is what I have so far:
int factor, num;
cout << "What number do you want factored?" << endl;
cin >> num;
int num = 0;
int factor = 0;
cout << "What number do you want factored?" << endl;
cin >> num;
for(int i = 2; i < num ; i++)
{
if(num % i == 0)
{
cout << i << " ";
factor++;
}
}
if(factor == 0)
{
cout << "Number is prime!" << endl;
}
It's faster if you test only up to the square root, while simultaneously printing out the numerToBeFactored/currentNumber.
Ex, the following is in python, I apologize:
1 2 3 4 5 6 7 8 9
numberToBeFactored = input("Enter yo shit: ");
for i in range(1, math.floor(math.sqrt(numberToBeFactored)) + 1):
if numberToBeFactored % i == 0:
print i;
print numberToBeFactored/i;