If f is surjective function, it means 2 things:

1. It has a value for all input points (Because f is a function).

2. It has a input point for any output point (Because f is surjective).

Same things if g is surjective also.

Then, if you take a point p in R, then you can always have a point (at least one) p_1, such that g(p_1) = p (Because g has something for any point p in the co-domain). If we consider the point p_1, there is at least one point p_2 in R such that, f(p_2) = p_1. So, combining these two,

For any point

gof(p_2) = g(f(p_2)) = g(p_1) = p

So, for any point p, there exists (at least) one point p_2, such that, gof(p_2) = p. proves that gof is surjective.

For the other part, it is better to give an example. Consider.

f(x) = ln(abs(x)).

g(x) = e^x.

g is clearly not surjective, because it maps only to positive values in the range. But, fog is surjective. Because,

fog(x) = f(g(x)) = f(e^x) = ln(e^x) = x, which is same as identity, that means, it is surjective.

Salahuddin

Maths online