Need a project done?

C++ Programming Developer

Search This Blog

How to Calculate Prime Factors?


#include <iostream>

using namespace std;

int main()
{
cout << "Enter a number: ";
int num;
cin >> num;

for (int i=2; i <= num; i++)
{
 while(num % i == 0)
 {
   num /= i;
   cout << i << " ";
 }
}
cout << endl;
return 0;
}

No comments:

Post a Comment

"Don't let anyone ever make you feel like you don't deserve what you want."