I would start by replacing
cout << "enter the number of row for second matrix=";
cin >> r2;
cout << "enter the number of column for second matrix=";
cin >> c2;
cout << "enter the second matrix element=\n";
for (int i = 0; i < r1; i++)
{
for (int j = 0; j < c1; j++)
{
cin >> m2[i][j];
}
}
with
cout << "enter the number of row for second matrix=";
cin >> r2;
cout << "enter the number of column for second matrix=";
cin >> c2;
cout << "enter the second matrix element=\n";
for (int i = 0; i < r2; i++)
{
for (int j = 0; j < c2; j++)
{
cin >> m2[i][j];
}
}