Iteration problem

I have a problem where I have 8 values needed to be worked out by iteration. The thing is each time you iterate you need to use the values you obtained last time you iterated. Any ideas how can I do it?
*Hint* max no of iterations is 3 times.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>

using namespace std;
 float itr [5][5];
 float V, V1, r;

float iterate (float m, float n) {

 for (int m = 1; m < 3; m++) {
    for (int n = 1; n < 4; n++) {
        itr [m][n] = 0.25 * (itr [m-1][n] + itr [m][n-1] + itr [m][n+1] + itr [m+1][n]);
        V1 = itr [1][1];
 }
 }
return 1;
}

float residue (float o, float p) {
r = (o - p)/o;
return r;

}

int main(){

    float z, s;
  for (int i = 0; i < 3; i++){
	for (int x = 0; x < 5; x++) {
		for (int y = 0; y < 5; y++)
		{
			itr [0][y] = 20;
			if (x > 0 && x < 5) {
                itr [x][4] = 30;
                itr [x][0] = 0;
                itr [x][3] = 5;
			}
			if (x>=3 && x<5) {
                itr [x][1] = 0;
                itr [x][2] = 0;
			}
			if (x>=1 && x < 3)	 {
                itr [x][1] = 5;
                itr [x][2] = 5;
                V = itr [1][1];
			}

        z = iterate(x,y);
        itr [3][3] = 0.25 * (itr [2][3] + itr [3][2] + itr [4][3] + itr [3][4]);
        itr [4][3] = 0.25 * (itr [3][3] + itr [4][2] + itr [4][4]);
        cout << "  " ;
        cout << itr [x][y];

		}
		cout << endl;
	}
	cout << endl;
    s = residue(V1, V);
    if (r < 0.02)
        break;
  }
    return 0;
}
Topic archived. No new replies allowed.