frain8

Untitled

Nov 16th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /* Dasproc C - 2019
  2. William Handi Wijaya
  3. 0087
  4.        
  5. Program untuk menghitung berapa kali fungsi
  6. rekursi dipanggil..
  7. */
  8.  
  9. #include <stdio.h>
  10.  
  11. void rekursi(int x, int *counter, int temp);
  12.  
  13. int main(void)
  14. {
  15.     int x;
  16.     int counter = 0;
  17.     int temp = 0;
  18.     scanf("%d", &x);
  19.     rekursi(x, &counter, temp);
  20.     counter %= 1000001;
  21.     printf("%d\n", counter);
  22.     return 0;
  23. }
  24.  
  25. void rekursi(int x, int *counter, int temp)
  26. {
  27.     temp = *counter;
  28.     temp++;
  29.     *counter = temp;
  30.     if (x <= 0)
  31.     {
  32.         return;
  33.     }
  34.     rekursi(x - 1, counter, temp);
  35.     rekursi(x - 2, counter, temp);
  36.     rekursi(x / 2, counter, temp);
  37.     rekursi(x / 3, counter, temp);
  38.     return;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment