gpt4 book ai didi

在C中递归地将8位数字转换为8位二进制

转载 作者:行者123 更新时间:2023-11-30 21:37:20 28 4
gpt4 key购买 nike

我如何用 C 语言编写一个递归解决方案来实现这一点?例如,如果我输入9,它应该输出00001001

最佳答案

#include <stdio.h>
#include <stdint.h>

void p(uint8_t n, int times){
if(times){
p(n >> 1, times-1);
putchar("01"[n & 1]);
}
}

void print_bin8(uint8_t num){
p(num, 8);
}

int main(void){
print_bin8(9);
return 0;
}

关于在C中递归地将8位数字转换为8位二进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34800561/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com