This probably isn't the most sophisticated way, but we can easily solve this just by plugging in different numbers.
Let f(x) = x2 + 6x + 9
f(1) = 12 + 6(1) + 9 = 1 + 6 + 9 = 16
f(2) = 22 + 6(2) + 9 = 4 + 12 + 9 = 25
f(3) = 32 + 6(3) + 9 = 9 + 18 + 9 = 36
f(4) = 42 + 6(4) + 9 = 16 + 24 + 9 = 49
So we can see that there are only 2 positive integers x that satisfy 20 < f(x) < 40
They are: x = 2 and x = 3