Factors and Prime Numbers

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;

for(factor=1;factor<=num;factor++)
{
if(num%factor==0)
{
cout << factor << " ";
}
}
{
if(???????)
{
cout << "Number is prime!" << endl;
}
}
return 0;
}
I guess test this out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	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;
	}
Thanks! I figured it out. Appreciate the help
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;

Topic archived. No new replies allowed.