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);
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);
}
if you like the answer please provide a thumbs up.
Use a C++ program to run your code that prompts the user to enter an integer,...
In c++ please .. Write a program that prompts the user to enter a four-digit integer and displays the number in reverse order.
C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".
C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...
I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...
c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...
5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. 1 largest = None 2 smallest = None 3 while True: 4...
Write a program that prompts the user to enter a binary string and displays the corresponding decimal integer value. For example, binary string ‘10001’ is 17 (1*24 +0*23 +0*22 +0*2 + 1 = 17) A sample run : Enter a binary: 10001 17 Enter second integer: 110 6 Use python.
IN JAVA 1. Create a program that prompts the user for an integer and then displays a message indicating whether or not the number is a perfect square. This can be determined by finding the square root of a number, truncating it (by casting the double result), and then squaring that result 2. Write a program that prompts the user for two numbers. The first number is a minimum value and the second number is a maximum value. RandomNum then...
Language is C 1. Palindrome Write a program that prompts the user for a positive integer number and output whether the number is a palindrome or not. A palindrome number is a number that is the same when reversed. For example, 12321 is a palindrome; 1234 is not a palindromoe. You will write a function named as palindrome. The function will have two arguments, number and isPalindrome. Both arguments are pass-by-reference. The argument number is a pointer to a variable...
c++ with pseudocodes Write a program that prompts the user to enter exam marks. The program then displays the average mark, the highest mark and number of marks entered less than the average mark.