On top of the answer by Emily L. Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.
On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.
On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.
On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors anand output \$n\$.
On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors an output \$n\$.
On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors and output \$n\$.
On top of the answer by Emily L. you can add a simple primality test as an exit condition for the loop, this will also avoid a lot of iterations.
while(number!=1 && div <= sqrt(number))
Where sqrt(number)
is the square root of the number in each iteration.
If \$ n \$ does not have divisors \$ < \sqrt{n} \$, then \$ n \$ is prime and thus you can stop looking for larger prime factors an output \$n\$.