C语言程序:将整数不断除以2并排序
#include <stdio.h> #include <string.h> #include <stdlib.h>
int main() { int i = 32; char s[100] = ''; while(1) { char temp[10] = {0}; sprintf(temp, '%d', i); strcat(s, temp); i /= 2; if (i < 1) break; } int len = strlen(s); for (int i = 0; i < len; i++) { for (int j = 0; j < len - i - 1; j++) { if (s[j] < s[j + 1]) { char tmp = s[j]; s[j] = s[j + 1]; s[j + 1] = tmp; } } } printf('%s\n', s); return 0; }
原文地址: https://www.cveoy.top/t/topic/lj49 著作权归作者所有。请勿转载和采集!