Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void factorial(uint32 n, out double result)
- {
- if ( n <= 1) {
- result = 1.0;
- } else {
- double partial_result;
- uint32 next_n = n - 1;
- factorial(next_n, out partial_result);
- result = n * partial_result;
- }
- }
- void main()
- {
- double result;
- uint32 n = 5;
- factorial(n, out result);
- stdout.printf("%g\n", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement