summaryrefslogtreecommitdiff
path: root/reference/C/TECHNIC/itter_rec.html
blob: 73998b02db7fdaae35c118e4e1492dddf2511871 (plain)
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
<title>Iteration vs Recursion.</title>
<body bgcolor=#f5deb3>
<hr>
<center>
<h1>Iteration vs Recursion</h1>
</center>
</hr>

Most problems that can be solved with iteration (
<a href=../SYNTAX/for.html>for</a>, 
<a href=../SYNTAX/while.html>while</a>, 
<a href=../SYNTAX/do.html>do</a> 
loops) can
also be solved with recursion. Pros and cons are:
<ul> 
<li>Iteration code will be faster and will use less resources.
<li>Recursion normaly looks more like the original formula.
</ul>
Anyway up, as an example of both technics here is some code to give the 
factorial of a number.
<a href=../EXAMPLES/fact1.c>Iteration</a>------
<a href=../EXAMPLES/fact2.c>Recursion</a>
<hr>
<p>
<center>
<table border=2 width=80% bgcolor=ivory>
<tr align=center>
<td width=25%>
<a href="../cref.html" target="_top">Top</a>
</td><td width=25%>
<a href="../master_index.html" target="_top">Master Index</a>
</td><td width=25%>
<a href="../SYNTAX/keywords.html" target="_top">C Keywords</a>
</td><td width=25%>
<a href="../FUNCTIONS/funcref.htm" target="_top">Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address> Martin Leslie 
<script language="JavaScript">
<!--  //
document.write(document.lastModified);
// -->
</script>
</address>