Question: Define a structure `DynamicMatrix` that represents a dynamic 2D matrix using pointers. The structure should contain pointers to dynamically allocated rows, each of which is a dynamically allocated array of integers. Write a C program that:
→ Allocates memory for an `m x n` matrix, where `m` and `n` are provided at runtime.
→ Provides functions to set and get values in the matrix.
→ Implements a function to transpose the matrix (i.e., swap rows and columns).
→ Ensures all dynamically allocated memory is properly managed and explain how you prevent memory leaks in your implementation.