Can i have a better logic to rotate a 2d array in clockwise direction

Can i have a better logic to rotate a 2d array in clockwise direction only clockwisedirection

Yeah you can use a temporary array and then swap them.

Can you share the code of it

It would be a good home work exercise for you. If I will do the coding, you will not learn. And remember that having good implementation is a skill that comes with practice.