Question: While loops Write a C + + program that asks the user for an integer and then prints out all its factors. Recall that if

While loops
Write a C++ program that asks the user for an integer and then prints
out all its factors.
Recall that if a number x is a factor of another number y, when y is
divided by x the remainder is 0.
Validate the input. Do not accept a negative integer.
Sample run of program:
Enter a positive integer:Invalid input! Try again:The factors of 42 are 12236714
Hint:
You need a variable called num to hold the input
and a variable called factor that would change in a loop
One while loop for validating num (print "invalid input" while num is negative)
One while loop for printing the factors
The factor variable is initialized to 1.
Print "The factors of " "are" (make sure to fill in the blank)
In the factor printing loop,
check if num is divisible by factor (starting from 1)
If so, print the value in factor along with a space
increase factor by 1
What should the condition of this while loop be?
(factor is going to increase by 1 until......)
While loops Write a C + + program that asks the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!