Consider the following code: for i= m to n increment 2 { print "hello!" } assuming m < n and exactly one of (m,n) is even, how many times will hello be printed? op 1: (n - m + 1)/2 op 2: 1 + (n - m)/2 op 3: 1 + (n - m)/2 if m is even, (n - m + 1)/2 if m is odd op 4: (n - m + 1)/2 if m is even, 1 + (n - m)/2 if m is odd
Answers
Answered by
42
if u consider m=5 and n=10 which satisfies m<n and any of m or n is even the for first loop m=5 hello is printed then it is incremented by 2 then m=7 again hello is printed as it is less than 10 then again m is incremented to 9 hello is printed total hello are 3 then for option 1 (10-5-1)/2=3 it matches
Similar questions