## programming ##


#1

Screenshot (98)
how many times d=d+1 will execute
please explain


#2

As you might notice if clause is executed for i, j, k each in {1,2,3…20}. So i will be anything between 1-20. Same for j and k.

Now the ((i+j+k)%2)==0 means that i+j+k should be even(sum of i,j and k should be even). So d = d+1 is executed for all combinations of i,j,k where there sum is even.

Now we look the i,j,k in terms of even and odd. There are 3 rules for sum of odd even(you might know them)

  1. Sum of two even numbers will always even

  2. Sum of 2 odd numbers will always even (3+5=8)

  3. Sum of an odd and even number will always be odd.

So you can look the below table
image

Total no of time the if clause is executed 202020(as it is nested loop)=8000
The d=d+1 will be executed only when if clause is true which we can see the half of time will be true(from above table 4 times out of 8). So total no of times d=d+1 is executed 4000