0% found this document useful (0 votes)
9 views1 page

Recursive Factorial Function Flowchart

The document describes a recursive function called fact that calculates the factorial of a given number. It shows the function being called recursively with different input values and the corresponding stack frames being generated.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Recursive Factorial Function Flowchart

The document describes a recursive function called fact that calculates the factorial of a given number. It shows the function being called recursively with different input values and the corresponding stack frames being generated.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

^ ->| |

Frame | | | |
Number - | | |============| int fact (int n)
| | | | i = 3 | {
| | | |------------| if (0 == n) {
| | | | f = ? | return 1; <-------- PC
#4 main() < | | |------------| }
| | | | | else {
| | -+->|------------| ---> return n * fact (n - 1);
| -+-+--+-----o | | }
= | | |============| | }
| | | | n = 3 | |
| | | |------------| | main ()
#3 fact (3) < | | | o---------+- {
| -+-+->|------------| | | int i;
| | | --+-----o | | |
= | | |============| | | for (i = 0; i < 10; i++) {
| | | | n = 2 | | -> int f = fact (i);
| | | |------------| | printf ("%d! = %d\n", i , f);
#2 fact (2) < | | | o------+--| }
| | | ->|------------| | }
| | -+--+-----o | |
= | | |============| |
| | | | n = 1 | |
| | | |------------| |
#1 fact (1) < | | | o------+--|
| | | |------------| |
| ---|--+-----o |<-+------- FP
= | |============| | |
| | | n = 0 | | |
| | |------------| | |
#0 fact (0) < | | o--------- |
| | |------------| |
| --+-----o |<--------- SP |
= |============| |
| | Red Zone | v
| \/\/\/\/\/\/\/ Direction of
#-1 < \/\/\/\/\/\/\/ stack growth
| | |

You might also like