Advertisement
fsb4000

vala

Jul 17th, 2020
3,737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 0.35 KB | None | 0 0
  1. void factorial(uint32 n, out double result)
  2. {
  3.   if ( n <= 1) {
  4.       result = 1.0;
  5.   } else {
  6.      double partial_result;
  7.      uint32 next_n = n - 1;
  8.      factorial(next_n, out partial_result);
  9.      result = n * partial_result;
  10.   }
  11. }
  12.  
  13. void main()
  14. {
  15.   double result;
  16.   uint32 n = 5;
  17.   factorial(n, out result);
  18.   stdout.printf("%g\n", result);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement