Change while to for or if-else.

I need to break down a number on prime numbers.I mean if i've 42.
42|2
21|3
7 |7
1

So, those numbers must be printed in the console and in a txt.

Thank you.

1
2
3
4
5
6
7
8
9
  int comp(int i, int a){
while (a!=0){
        if ((a!=0) && (a%i== 0)){
            cout <<i <<endl;
               a=a/i;
            }
        else i=i+1;
               }
               }
Topic archived. No new replies allowed.