Systemnahe Programmierung in C: Endrekursion, Sprünge und Schleifen |
1/* ggt in endrekursiver Form */
2
3unsigned long
4ggt (unsigned long x, unsigned long y)
5{
6 if (x == y)
7 return x;
8
9 if (x > y)
10 return ggt (x - y, y);
11
12 return ggt (y, x);
13}
|
|
1unsigned long
2ggt1 (unsigned long x, unsigned long y)
3{
4start:
5 if (x == y)
6 return x;
7
8 if (x > y)
9 {
10 x = x - y;
11 goto start;
12 }
13 {
14 unsigned long t = x;
15 x = y;
16 y = t;
17 goto start;
18 }
19}
|
1unsigned long
2ggt (unsigned long x, unsigned long y)
3{
4 while (x != y)
5 {
6 if (x > y)
7 x = x - y;
8 else
9 {
10 unsigned long t = x;
11 x = y;
12 y = t;
13 }
14 }
15
16 return x;
17}
|
Letzte Änderung: 31.10.2011 | © Prof. Dr. Uwe Schmidt |