-
problem
Hi, I am trying to find out how to create a program which will print the prime factors of a number inputed. my code is
Code:
#include <iostream>
using namespace std;
int main()
{ int x;
cin>>x;
int i=1;
while(i<x)
{
if (x%i==0)
{
cout<<i<<"\n";
x=x/i;
}
else
{i++;
}
cout<<x;
}
}
is it possible to make a code that would add all this factors??
-
For this to work properly i needs to be a prime. You should start with a decent list of primes, if you don't want to implement a prime number test.
Also a good compile does not mean that your program is free of logic errors. Compiling doesn't detect those.