就是不断除二求余在除二求余,然后将余数从下到写出来,这样,10011100就是156的二进制
- #define _CRT_SECURE_NO_WARNINGS
- #include
-
- int main()
- {
- int n = 0;
- int arr[40] = { 0 };
- scanf("%d", &n);
-
- int i = 0;
- while (n)
- {
- arr[i] = n % 6;//6进制,%6/6,参考10进制转2进制
- i++;
- n = n / 6;
- }
- for (i--; i >= 0; i--)//i进去就减1,因为要打印下标,从最后下标逆序打印
- {
- printf("%d", arr[i]);
- }
- return 0;
- }
- #define _CRT_SECURE_NO_WARNINGS
- #include
-
- int main()
- {
- int n = 0;
- int arr[40] = { 0 };
- scanf("%d", &n);
-
- int i = 0;
- while (n)
- {
- arr[i] = n % k;//k是要转的进制
- i++;
- n = n / k;
- }
- for (i--; i >= 0; i--)//i进去就减1,因为要打印下标,从最后下标逆序打印
- {
- printf("%d", arr[i]);
- }
- return 0;
- }