Advertisement
mohsentux

log_n_buggy

May 27th, 2022
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. double log_n(double n) { // Big O(log n) Logarithmic  // recursive
  5.     if (n != 0) {
  6.         n = floor(n / 2);
  7.         log_n(n);
  8.     }
  9.     return n;
  10. }
  11.  
  12. int main() {
  13.  
  14. std::cout << log_n(8.0) << '\n';
  15.  
  16. return 0;
  17. }
  18.  
  19. // returns 4 instead of 3. I thought it was because I used int first but the bug is still here.
  20. // for 7.0 it returns 3 instead. what am I doing wrong?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement