Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that requests an integer and displays: - all factors of the inpu

ID: 3849504 • Letter: W

Question

Write a program that requests an integer and displays: - all factors of the input (numbers that evenly divide the input) (i.e. 1, 2, 3, 5, 6, 10, 15 are all factors of 30) - if the input is prime (input that is only divisible by 1 and itself) Request an integer value between 1 and 100. validate input value type and range via a do while loop. Display all factors of the value. Indicate if the number is prime Output Example: Enter an integer between 1 and 100: 5.3 Invalid value. Enter an integer between 1 and 100: 103 Invalid value. Enter an integer between 1 and 100: 56 Factors of 56: 1 2 4 7 8 14 28 56 output Example (Prime Number): Enter an integer between 1 and 100 5 Factors of 5: 1 5 5 is a prime number.

Explanation / Answer

#include <iostream>

#include <cmath>

using namespace std;

int main()
{
int number, temp = 1;
cout << "Enter the number to determine its factors : " << endl;
cin >> number;
if( number == floor(number) )
{
cout<< "true";
}
else
{
cout<< "false";
}
cout << "The factors of " << number << " are : " << endl;
while (temp <= number)
{
if (not(number % temp))
cout << temp << " ";

temp++;
}
cout << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote