2020年6月14日 星期日

10進位轉2進位

#include <iostream>
using namespace std;
int main()
{
    int n=7;
    string r="01";
    string s="";
    while (n>=1)
    {
        int k=n%2;
        s = r[k]+s;
        n=n/2;
    }
    cout << s << endl;
}