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 is a factor of another number when is
divided by the remainder is
Validate the input. Do not accept a negative integer.
Sample run of program:
Enter a positive integer:Invalid input! Try again:The factors of are
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
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
If so print the value in factor along with a space
increase factor by
What should the condition of this while loop be
factor is going to increase by until......
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
