Factor

A factor is an integer that can be divided evenly into another number or in other words factors of a number are numbers that multiply to form a product.

Logic

To print all the factors of a particular number we have to iterate through all the smaller numbers up to the given number. If the user given number is completely divisible by any number then it is a factor of that number.

Program

#include <iostream>

using namespace std;

int main() {

    int i, num;

    // Take input from user
    cout << "Enter any number : ";
    cin >> num;

    cout << endl << "All factors of " << num << " are : " << endl;
    
    for(i = 1; i <= num; i++) {

        if(num % i == 0) {
            cout << i << " ";
        }
    }

    return 0;
}

Output

Enter any number : 50
All factors of 50 are :
1 2 5 10 25 50