วันอังคารที่ 13 เมษายน พ.ศ. 2553

Decimal to Binary

#include <iostream>

#include <string>

using namespace std;

string compute(int n){

     if(n==0)

          return "";

     else if(n%2==0)

          return compute(n/2)+"0";

     else

          return compute(n/2)+"1";

}

int main(){

     cout<<compute(14)<<endl;

     return 0;

}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น