C语言实现十进制转换为三进制
#include <stdio.h> #include <math.h>
void decimal_to_ternary(int decimal) { int ternary = 0, i = 0; while (decimal != 0) { ternary += (decimal % 3) * pow(10, i); decimal /= 3; i++; } printf('The ternary equivalent is: %d\n', ternary); }
int main() { int decimal; printf('Enter a decimal number: '); scanf('%d', &decimal); decimal_to_ternary(decimal); return 0; }
原文地址: https://www.cveoy.top/t/topic/ndk8 著作权归作者所有。请勿转载和采集!