> but can u tell why we get such an output.
Because your code is broken.

Broken code produces whatever it feels like, regardless of what you might expect / like / desire / hope for.

Use a compiler which can check your printf / scanf format strings (like I posted), and don't run any code which has warnings in it.