C++ Program to Print All Divisors of Number using For Loop

C++ Program to Print All Divisors of Number using For Loop

Write C++ Program to Print All Divisors of Number using For Loop

// CPP Program to Print All Divisors of Number using For Loop

#include <iostream>

using namespace std;

int main()
{
	int n, div;

	cout << "Enter the number :--> ";
	cin >> n;

	cout << "All the divisors of " << n << " are :-->  ";
	for(div = 2; div < n; div++)
	{
		if(n % div == 0)
		{
			cout << div << " ";
		}
	}

	return 0;
}

Output:

Enter the number :--> 56
All the divisors of 56 are : 2 4 7 8 14 28