Find factors and check if prime.

Program not working, any ideas.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    long double a = 1;
    long double b = 0;
    long double c = 0;
    long double n = 10000;
    while (a< n){
     if (fmod(n, a) == 0){
        c = a;
        ++a;
        if ((fmod(c, 2)!=0) && (fmod(c, 3)!= 0)){
            b = c;
            cout << b << endl;
        }
    }
}
}
Your problem is not clear.

What are b and c?

Are you trying to find all the factors of n?

Are you trying to find only prime factors or are you trying to determine if n is prime? (I initially presumed the latter, but you appear to be trying to do the former.)


Just eyeballing it, I'd be concerned that your loop does not modify a if a is not a factor of n.
Trying to find the factors of n and see if they are prime. I tried different things and keep getting 1.
Are you sure that's your homework assignment: find all prime factors of n?

If it is, you have three problems to solve:
1) determine if a number is prime
2) find all prime numbers between 2 and sqrt(n), inclusive
3) display those numbers from part 2 that are integer factors of n

Try to solve each problem, in order.

Hope this helps.
Need help with the program.
Topic archived. No new replies allowed.