Sum Of All Submatrix From A given Matrix - Approach 3.cpp

wrong answer

According to video code should be something like this check the logic.

And if we give custom input for submatrix how to maintain y>x??

code:- https://ide.codingblocks.com/s/454374

question:- https://online.codingblocks.com/app/player/189104/content/180055/6688/lecture

hello @dasvishal60

you are not initilaising 2d array correctly.
it should be like
int a[row][cow]={ {1,1,1} , {1,1,1} , {1,1,1} }

1 Like

need to ask few more doubts from sir’s method i have written questions in code in the form of comment please answer them

this code also giving wrong ans :sweat_smile:

code:-https://ide.codingblocks.com/s/454374

@dasvishal60

see what u r asking is not related to logic of the problem.

here in the code we are dynamically allocating 2d array.
and to understand that u need to first learn about dynamic memory allocation, new operator , how to allocate 1 d array dynamically using new operator and how to allocate 2d array dynamically using new operator.
so learn about it , and then every single line will make sense to u

pls specify what input u are giving

IN THIS CODE ELEMENTS ARE ALL 1

And in previous code if we want to find sum of 3 * 3 or 2 * 3 then what changes are required ??

I tried but it didn’t work

@dasvishal60

is answer is 120 ?

the logic is generic , it will work for matrix of any size. u dont have to do any changes

the answer should be 100 I figured out what was wrong thanks for the help :smiley:

and dynamic memory is after 2 sets so hopefully, I’ll figure out quarries from sir method after that when I reach there.

yeah after studying dma , u can understand this easily

1 Like