I am getting an output on the computer from a formula which I am not able to understand

55 Views Asked by At

((n - Math.Abs(j / 2) - 1) * (n - Math.Abs(j / 2))) / 2 + i + 1

this line of code is giving output of 1 for values set n=4;j=7;i=0

when i do manually on paper i am getting 0/3 =0 what am i doing wrong and what is this formula called provided this formula exists.

To further elborate my manual calculation

step 1:   ((4-Math.Abs(7/2)-1) *(4-Math.Abs(7/2)))/2+0+1

step 2:   ((4-Math.Abs(3.5)-1) *(4-Math.Abs(3.5)))/3 

__________________________________________^ this "3" is wrong!!!!

step 3:   ((0.5-1) *(0.5))/3

step 4:   ((-0.5)*(0.5))/3

step 5:  (-0.25)/3

step 6:  0/3=0


 i am getting zero
 but computer is giving 1 as output
1

There are 1 best solutions below

0
On BEST ANSWER

I'm assuming integer division.

((4-Math.Abs(7/2)-1)*(4-Math.Abs(7/2)))/2 + 0 + 1
((4-3-1)*(4-3))/2+0+1
(0*1)/2+0+1
0/2+0+1
0+0+1
1