Write a C program that asks the user for an integer and then

Write a C++ program that asks the user for an integer and then prints out all its factors in increasing order. The factors of a number are all those numbers that can divide evenly into the number with no remainder. The greatest factor of a number is the number itself, so you can always list all the factors of any number because you have a stopping point. For example 1, 2, 3, 4, 6 and 12 are factors of 12.

Solution

This is a simple c++ program to display the factors of the number given in input. #include using namespace std; int main() { int n,i; cout << \"Enter an integer \";// read number cin >> n; cout << \"Factors of \" << n << \" are: \" << endl; for(i=1;i<=n;i++)// loop to calculate and print factors { if(n%i==0) // if the remainder is zero then it is a factor of that number cout << i << endl; } return 0; }
Write a C++ program that asks the user for an integer and then prints out all its factors in increasing order. The factors of a number are all those numbers tha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site