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

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

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

#include <iostream>

using namespace std;

int main()
{
	int n;
	cout << "Enter the number :--> ";
	cin >> n;

	int div = 2;  //divisor

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

	return 0;
}

Output:

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

≪ Previous | Next ≫