Define the method below to return the lowest factor of an ar

Define the method below to return the lowest factor of an arbitrary integer. the lowest factor is the smallest number greater than 1 that will that will divide evenly into the parameter (which will be 2 or higher)

Solution

//can be used in java or c++ (since language not mentioned in the question) public static int smallestFactor(int n){ //function declaration for (int i = 2; i*i <= n; i++) { //iterating till square root of n if (n % i == 0){ return i; //return as soon as the smallest factor found. } } return n; //prime number }
Define the method below to return the lowest factor of an arbitrary integer. the lowest factor is the smallest number greater than 1 that will that will divide

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site