#include <stdio.h> #include <stdlib.h> const int N=4; void output(char x[], int n); // 函数声明 // 排序函数声明 void pao(char a[],int n); int main() { char string[N] = {‘2‘,‘0‘,‘1‘,‘9‘}; int i; printf("排序前: \n"); output(string, N); pao(string,N); printf("\n排序后: \n"); output(string, N); printf("\n"); system("pause"); return 0; } // 函数定义 // 函数功能描述:输出包含有n个元素的字符数组元素 // 形参:字符数组,以及字符数组元素个数 void output(char x[], int n) { int i; for(i=0; i<N; i++) printf("%c", x[i]); } // 函数定义 // 函数功能描述:对一组字符由大到小排序 // 形参:字符数组,以及字符数组元素个数 void pao(char a[],int n) { int i,t,j; for(j=0;j<N-1;j++) for(i=0;i<N-1-j;i++) if(a[i]<a[i+1]) { t=a[i]; a[i]=a[i+1]; a[i+1]=t; } }

原文:https://www.cnblogs.com/201qx/p/11973487.html