#include <iostream>
#include <cmath>
using namespace std;
// A function to print all prime factors of n
void primeFactors(int *n){
while ((*n) % 2 == 0)
{
cout << 2 << " ";
(*n) /= 2;
}
double x = sqrt(*n);
for (int i = 3; i <= x; i += 2){
while ((*n) % i == 0){
cout << i << " ";
(*n) /= i;
}
}
if((*n) != 1)
cout << (*n);
}
int main(){
int n;
int *p;// Pointer variable
cout << "Enter number: "; cin >> n;
p = &n;// reference into a pointer variable,
cout << "Prime factors: " << endl;
primeFactors(p);
}
Comments
Leave a comment