Download presentation
Presentation is loading. Please wait.
Published byLauren Fisher Modified over 9 years ago
1
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion 55 5
2
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 5 55 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); }
3
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 544 4 4 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); }
4
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 3 3 3 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); }
5
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 2 2 2 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); }
6
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 1 11 1
7
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 1 0 0 1
8
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 11 1
9
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 11 1 2
10
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 43 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 11 1 2 6
11
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 543 2 int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 11 1 2 624
12
int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } void main () { Int Sum; : Sum = fact (5); : } 120 24 5
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.