Advertisement
avisrivastava254084

Untitled

Oct 29th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.19 KB | None | 0 0
  1. string toBinary(int n) {
  2.     if (n==0) return "0";
  3.     else if (n==1) return "1";
  4.     else if (n%2 == 0) return toBinary(n/2) + "0";
  5.     else if (n%2 != 0) return toBinary(n/2) + "1";
  6. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement