Floating Point error

float avg = float(br[n-1][n-1]) / (2*n - 3);

worked

float avg = (br[n-1][n-1] * 1.0)/ (2*n - 3);

gave wrong ans

Is the second method not a valid way to convert int to float ?

Yes, the second process is not a correct process, because you want to convert the R.H.S from int to float, so after doing this mathematical operation (br[n-1][n-1] * 1.0)/ (2*n - 3) whatever the result comes, only the integer part of that result will be considered as you have taken other variable and array except the avg are of integer type(i suppose). So, to convert the result from int to float you should go for the first process as you are converting the whole result from int to float in that particular process.