fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void binaryNormal(int decimalInteger) //This function does NOT use recursion
  5. {
  6. string buff = "";
  7. while (decimalInteger != 0)
  8. {
  9. int remainder = decimalInteger % 2;
  10. buff += remainder + '0';
  11. decimalInteger /= 2;
  12. }
  13.  
  14. for(int i = buff.length() - 1; i >= 0; cout << buff[i--]);
  15. cout << endl;
  16. }
  17.  
  18. void binaryRecursion(int decimalInteger) //This function uses recursion
  19. {
  20. int remainder = decimalInteger % 2;
  21. if (decimalInteger / 2 > 0) binaryRecursion(decimalInteger / 2);
  22.  
  23. cout << remainder;
  24. }
  25.  
  26. int main() {
  27. // your code goes here
  28. binaryNormal(101);
  29. binaryRecursion(101);
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1100101
1100101