C++ Program to Find Divisors of a Number.program takes number from the input and runs a while loop until the temporary variable reaches the given number. The temporary number is printed on the screen if the given number is completely divisible by the temporary variable.
C++ Program to Display the Factors of the Given Number
#include <iostream>
#include<conio.h>
using namespace std;
int main()
{
int n, i;
cout << "Enter the number:";
cin >> n;
cout << "Factors of " << n << " are: " << endl;
for(i = 1; i <= n; ++i)
{
if(n % i == 0)
cout << i << endl;
}
return 0;
}
Output of Program
Enter a positive integer: 60 Factors of 60 are: 1 2 3 4 5 6 12 15 20 30 60