Matrix rotation

I have solved the problem on my own but the expected output doesn’t come.Plz help through this and review my code.Here is my code.

#include
using namespace std;

int rotateMatrix(int a[][10], int rows, int cols)
{
//1st step is to calculate the transpose of the matrix

for(int i = 0; i < rows; i++)
{
	for(int j = 0; j < cols; j++)
	{
		if(i < j) //Here if the element of the row is less than the element of the column then only swapping is performed.
		{
			int temp = a[i][j];
			a[i][j] = a[j][i];
			a[j][i] = temp;
		}
	}
}

//2nd step is to either interchange the rows or to reverse the column.
//Here i can do the first method that is interchanging the column.

for(int i = 0; i < rows; i++)
{
	for(int j = 0; j < (cols/2); j++)
	{
		int temp = a[i][j];
		a[i][j] = a[i][cols - 1 - j];
		 a[i][cols - 1 - j] = temp; 
	}
}

}

int main()
{
int rows, cols;
cin>>rows>>cols;

int a[10][10];
for(int i = 0; i < rows; i++)
{
	for(int j = 0; j < cols; j++)
	{
		cin>>a[i][j];
	}
	
	rotateMatrix(a, rows, cols);
	
	return 0;
}

}

hey @Ccranjan, you need to rotate the matrix 90 degrees anti-clockwise. So make the changes in first index instead of second.

here are the changes

for(int i = 0; i < rows/2; i++)
{
for(int j = 0; j < cols; j++)
{
int temp = a[i][j];
a[i][j] = a[rows - 1 - j][j];
a[rows - 1 - j][j] = temp;
}
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.