Nth multiple of 4

The following function returns the Nth multiple of 4. What is N ?

# python code start
def calc_nth_multiple_of_4():
    i = 0
    n = 0
    while (n < 11):
        i += 1
        if (i % 4 == 0):
            n += 1
    return i

Details and assumptions

The 1st multiple of 4 is 4 .


The answer is 11.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

The answer is 11 . This code iterates through integers i , and uses n to keep track of how many multiples of 4 we find. Once n == 11, the loop exits, and i contains the 11th multiple of 4. The function then returns i .

# python code start
def calc_nth_multiple_of_4():
    i = 0
    n = 0  # keeps track of how many multiples of 4 we've encountered
    while (n < 11):
        i += 1 

        # if i is a multiple of 4
        if (i % 4 == 0): 
            # increment n. i is the nth multiple of 4.
            n += 1
    return i

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...