You have to work on your code posting skills. Just copy your code as plain text to the text box and put code-tags around it.

Your indentation is completley messed up too (which could be related to the above problem).

Code:

if (flag==1)
printf("%d is prime\n", n); /*check flag for each "i" values if it is 1(true) and print n is "prime"*/
else
printf("%d is not prime\n", n); /*all others ( if it is 0(false) print "not prime"*/

You don't check the flag for each "i". You check the flag after the loop whether any value of "i" has set it to 0.

Just some additional comments:

1) You calculate the square root for "n" at each iteration although "n" doesn't change. Therefore it's better to calculate it once before the loop and then just use the stored value.

2) If your test fails when "i" is 2 (i.e. "n" is odd) all further even numbers (4, 6, 8, ...) will fail. Thus you should only loop through odd values for "i"

3) As soon as you find a value for "i" which divides "n" there is no need to try other values. You can just break out of the loop.

4) If you do break out prematurely there is really no need for a flag. Just test if "i" is equal to the square root of "n" after the loop to decide whether "n" is prime.

Bye, Andreas