See my edit.
Find prime factorization of 24 = 2 * 2 * 2 * 3.
Every time there's 2x of the same number (e.g. the 2 * 2), factor it outside. With the remaining numbers, repeat the factoring process until there are no more squares (2 * 3). This will require making an array or list of numbers, which I'm not sure if you've learned yet.
If you're just a beginner, I seriously wouldn't worry about outputting correct symbolic notation.
Edit: Apparently there's different methods than finding the prime factorization, see
https://castingoutnines.wordpress.com/2008/02/07/the-illini-method-for-simplifying-a-radical/
_______________________________________
Edit 2: So, instead of doing the prime factorization, you just need to check every square number below the sqrt(number) you're trying to simplify, to see if you're divisible by that number. If so, factor it out.
For example, 24. The square numbers below 24 are: 4, 9, 16.
Is 24 divisible by 16 --> no
Is 24 divisible by 9 --> no
Is 24 divisible by 4 --> yes! divide by 4 on the inside, multiple by sqrt(4) = 2 on the outside.
repeat process with 24 / 4 = 6 until there are no square divisible numbers under your number.
Sorry rushed because I have to leave for something, otherwise I'd totally just program this myself.