u can make it faster by incrementing counter by 2 when divisibilty by 2 fails.
u can further accelerate, by avoiding checking multiples of numbers already checked.(sieve of Eratosthenes)
Read sth about it at
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
also,
http://en.wikipedia.org/wiki/Primality_test
will help.
and...
personally, i feel checking till n/2 will be more efficient than sqrt(n). because sqrt(n) may take more steps.
u can also update the upper limit during each iteration
as
for (i=3;i<=n/i;i++)