begin Solve (A)
int i , j, done = 0;
float temp;
while (!done)
diff = 0.0;|
for i = 0 to n-1
for j = 0 to n-1
temp = A[ i,j ];
A[ i,,j ] = 0.2(A[ i,,j ]+A[i,,j+1]+A[i,,j-1]+ A[i-1,,j]+A[i+1,,j];)
diff += fabs (A[ i,j ] - temp);
endfor
endfor
if (diff/(n*n) < TOL) then done = 1; endwhile
end Solve