C++ Program to Print Factors of a Number using For Loop

C++ Program to Print Factors of a Number using For Loop

Write C++ Program to Print Factors of a Number using For Loop

// CPP Program to Print Factors of a Number using For Loop

#include <iostream>

using namespace std;

int main()
{
    int n, i;

    cout << "Enter a positive number :--> ";
    cin >> n;

    cout << "Factors of " << n << " are :--> ";

    for(i = 1; i <= n; i++)
    {
     	if (n % i == 0)
	 	{
            cout << i << " ";
        }
	}
}

Output:

Enter a positive number :--> 80
Factors of 80 are :--> 1 2 4 5 8 10 16 20 40 80