将字符串a下标值为偶数的元素由小到大排序,其它元素不变

    xiaoxiao2022-07-13  131

    /*将字符串a下标值为偶数的元素由小到大排序,其它元素不变*/ #include<stdio.h> #include<string.h> void main() { char a[]="labchmfye";//l b h f e char t; int i,j; for(i=0;i<7;i++) { for(j=i+2;j<9;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; j++; } } } printf("最总结果为:\n"); puts(a); }

    运行结果:

    最新回复(0)