Question

Use a C++ program to run your code that prompts the user to enter an integer,...

Use a C++ program to run your code that prompts the user to enter an integer, greater or equal to 2, and displays its largest factor other than itself.

To answer for this question, It is required that you use following two functions to complete the assignment.

a.     // Prompts the user to enter an integer: number >=2

        void getNumber( int& number);

b.     // returns the largest factor of n other than itself

        int getLargestNonSelfFactor(int n);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Code:

#include <iostream>

#include <cmath>

using namespace std;

void getNumber(int &num){

do{

cout<<"Enter a number greater than or equal to 2: ";

cin>>num;

}while(num<2);

}

int getLargestNonSelfFactor(int n){

int factor;

for(int i=3;i<n;i++){

if(n%i==0)

factor=i;

}

return factor;

}

int main() {

int num;

getNumber(num);

cout<<"Largest non self factor of "<<num<< " is "<<getLargestNonSelfFactor(num);

}

https://RichBasicManagement.kunlstudy.repl.run clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/final) clang++-7 pthre

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
Use a C++ program to run your code that prompts the user to enter an integer,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT