Question #47982

My instructor gave us an assignment composed of 4 problems. I was able to do 3 out of 4. I still have one but I have no idea how to write the program. The question is:
Write a program to allow the user to enter a number between 10 and 80 inclusive. You have to keep asking the user to enter a number in that range if he doesn’t (use do-while). Then call a function that will list all the combinations of two integers (other than 1*the number itself) that their multiplication is equal to the entered number. Example; if the user entered 36 then your output will be: <2, 18> <3, 12> <4, 9> <6, 6>.
Please help?

Expert's answer

#include <cmath>

#include <iostream>

using namespace std;

void print_multiplications(int n) {

bool first = true;

for (int i = 2; i <= sqrt(n); ++i) {

if (n % i == 0) {

if (!first) cout << ", ";

cout << "<" << i << ", " << n / i << ">";

first = false;

}

}

cout << endl;

}

int main() {

int n = 0;

do {

cout << "Input a number between 10 and 80: ";

cin >> n;

} while (n < 10 || n > 80);

print_multiplications(n);

}

#include <iostream>

using namespace std;

void print_multiplications(int n) {

bool first = true;

for (int i = 2; i <= sqrt(n); ++i) {

if (n % i == 0) {

if (!first) cout << ", ";

cout << "<" << i << ", " << n / i << ">";

first = false;

}

}

cout << endl;

}

int main() {

int n = 0;

do {

cout << "Input a number between 10 and 80: ";

cin >> n;

} while (n < 10 || n > 80);

print_multiplications(n);

}

``

## Comments

## Leave a comment