Let S be a semigroup, ℍ be the skew field of quaternions, and ψ: S → S be an anti-endomorphism. We determine the general solution of the functional equation
g
(
x
y
)
-
g
(
x
ψ
(
y
)
)
=
2
g
(
x
)
g
(
y
)
,
x
,
y
∈
S
,
g\left( {xy} \right) - g\left( {x\psi \left( y \right)} \right) = 2g\left( x \right)g\left( y \right),\,\,\,\,x,y \in S,
where g : S → ℂ is the unknown function. And when S = M is a monoid, we solve the functional equation
g
(
x
y
)
+
g
(
x
ψ
(
y
)
)
=
2
g
(
x
)
g
(
y
)
,
x
,
y
∈
M
,
g\left( {xy} \right) + g\left( {x\psi \left( y \right)} \right) = 2g\left( x \right)g\left( y \right),\,\,\,\,x,y \in M,
where g : M → ℍ is the unknown function.