File: itter_rec.html

package info (click to toggle)
c-cpp-reference 2.0.2-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 8,016 kB
  • ctags: 4,612
  • sloc: ansic: 26,960; sh: 11,014; perl: 1,854; cpp: 1,324; asm: 1,239; python: 258; makefile: 119; java: 77; awk: 34; csh: 9
file content (49 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download | duplicates (3)
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>