Are you trying to find only prime factors or are you trying to determine if n is prime? (I initially presumed the latter, but you appear to be trying to do the former.)
Just eyeballing it, I'd be concerned that your loop does not modify a if a is not a factor of n.
Are you sure that's your homework assignment: find all prime factors of n?
If it is, you have three problems to solve:
1) determine if a number is prime
2) find all prime numbers between 2 and sqrt(n), inclusive
3) display those numbers from part 2 that are integer factors of n