Code execution problem

when i used n^2 in place of n*n the code is giving unexpected output. why?

Why would they give same output?
n^2 in c++ is not equal to n*n, it means you are doing bitwise xor between n and 2, not raising the power of n to two.