Sum of all submatrix with time complexity=O(n^4)

sir as code wasnt available in the video i coded myself i just want to know is this code output right??
are all the cases covered

Yes your code is correct.