Mean ergodic theorems and iterative solution of linear functional equations