Recursive factorial function : function recursion « Function « C++ Tutorial

C++ Tutorial
1. Language Basics
2. Data Types
3. Operators statements
4. Array
5. Development
6. Exceptions
7. Function
8. Structure
9. Class
10. Operator Overloading
11. Pointer
12. File Stream
13. template
14. STL Introduction
15. string
16. vector
17. list
18. bitset
19. set multiset
20. valarray
21. queue stack
22. deque
23. map multimap
24. STL Algorithms Modifying sequence operations
25. STL Algorithms Non modifying sequence operations
26. STL Algorithms Binary search
27. STL Algorithms Sorting
28. STL Algorithms Merge
29. STL Algorithms Min Max
30. STL Algorithms Iterator
31. STL Algorithms Heap
32. STL Algorithms Helper
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C++ Tutorial » Function » function recursion 
7. 11. 3. Recursive factorial function
#include <iostream>
using std::cout;
using std::endl;

#include <iomanip>
using std::setw;

unsigned long factorialunsigned long )// function prototype

int main()
{
   for int counter = 0; counter <= 50; counter++ )
      cout << setw<< counter << "! = " << factorialcounter << endl;

   return 0;
}
unsigned long factorialunsigned long number )
{
   if number <= )
      return 1;
   else
      return number * factorialnumber - );
}
0! = 1
 1! = 1
 2! = 2
 3! = 6
 4! = 24
 5! = 120
 6! = 720
 7! = 5040
 8! = 40320
 9! = 362880
10! = 3628800
11! = 39916800
12! = 479001600
13! = 1932053504
14! = 1278945280
15! = 2004310016
16! = 2004189184
17! = 4006445056
18! = 3396534272
19! = 109641728
20! = 2192834560
21! = 3099852800
22! = 3772252160
23! = 862453760
24! = 3519021056
25! = 2076180480
26! = 2441084928
27! = 1484783616
28! = 2919235584
29! = 3053453312
30! = 1409286144
31! = 738197504
32! = 2147483648
33! = 2147483648
34! = 0
35! = 0
36! = 0
37! = 0
38! = 0
39! = 0
40! = 0
41! = 0
42! = 0
43! = 0
44! = 0
45! = 0
46! = 0
47! = 0
48! = 0
49! = 0
50! = 0
7. 11. function recursion
7. 11. 1. Demonstrate recursion
7. 11. 2. Print a string backwards using recursion
7. 11. 3. Recursive factorial function
7. 11. 4. The recursive fibonacci function.
7. 11. 5. The iterative factorial method.
w___w__w_._ja_v___a__2__s___.__c_o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.