i am having problem with this code of mine with below problem

i am not able to understand what is the problem

my code for this problem is

please help

i am having problem with this code of mine with below problem

i am not able to understand what is the problem

my code for this problem is

please help

From your code on ideone,

at line 28 —> (if(temp == ‘\n’)j–;), if newline occurs in temp variable, you are bringing column index one step behind, but temp variable still contains ‘\n’, hence due to line 29 —>(ch[i][j] = temp;), you are storing ‘\n’ in your two dimensional array, on which you will operate with your logic further,

hence due to wrong content in your 2D array, you are calculating wrong answer. You should add in your if-then statement at line 28 —> if(temp == ‘\n’){j–; cin>>temp; },