#include #include using namespace std; int main() { cout << "What positive integer do you want to factor? "; int n {0}; cin >> n; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } for (int factor {2}; factor <= n; ++factor) { //The n % factor == 0 keeps the inner for loop looping //as long as n is still divisible by the factor. //The n /= factor means n = n / factor //This causes n to get smaller and smaller. for (; n % factor == 0; n /= factor) { cout << factor << "\n"; } } return EXIT_SUCCESS; }