Here is source code of the C++ program which displays the factors of the given number. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
* C++ program to display the factors of the entered number
using namespace std;
int number, temp = 1;
cout << "Enter the number to determine its factors : " << endl;
cin >> number;
cout << "The factors of " << number << " are : " << endl;
while (temp <= number)
if (not(number % temp))
cout << temp << " ";
cout << endl;
$ g++ main.cpp $ ./a.out Enter the number to determine its factors : 6 The factors of 6 are : 1 2 3 6
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you liked this C++ Program, kindly share, recommend or like below!