下面程序的功能:将字符数组a中下标值为偶数的元素从小到大排列 其他元素不变。请填空。 include
下面程序的功能:将字符数组a中下标值为偶数的元素从小到大排列,其他元素不变。请填空。 include<stdio. h> include<string. h> main() { char a[]="clanquage", t; int i, j, k; k=strlen(A) ; for(i=0; i<=k-2; i+=2) for(j=i+2;j<k; j+=2) if(【 】) { t=a[i]; a[i]=a[j]; a[j]=t; } puts(A) ; printf("/n"); }
请帮忙给出正确答案和分析,谢谢!
参考解答
正确答案:a[j<a[i
本题考查排序算法,题目中通过双循环嵌套来实现,外层循环跳出待排序的元素,内层循环具体实现a[i到a[k-2之间偶数下标元素的排序,每次将最小的放在a[i中。所以空中填a[j<a[i。
相似问题
有以下程序: void f(int*x iht * y) { int t; t=*x;*x;=*y;
有以下程序: void f(int*x,iht * y) { int t; t=*x;*x;=*y;*y=t; } main() { int a[8]={1,2,3,4,5,6,7,8},i,*p,*q; p=a;q=&a[7]; while(
以下程序的运行结果是【 】。 include <stdio.h> main() { int x=1
以下程序的运行结果是【 】。 include <stdio.h> main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0:a++
若a=1 b=2 则表达式!(x=a)‖(y=b)&&0的值是______。请帮忙给出正确答案和分析
若a=1,b=2,则表达式!(x=a)‖(y=b)&&0的值是______。请帮忙给出正确答案和分析,谢谢!
以下程序的功能是输出如下形式的方阵: 13 14 15 16 9 10 11 12 5 6 7 8
以下程序的功能是输出如下形式的方阵: 13 14 15 16 9 10 11 12 5 6 7 8 1 2 3 4 请填空。 main() { int i, j, x; for(j=4; j
阅读下面语句 则程序的执行结果是【 】。 include 'stdio.h' main() { in
阅读下面语句,则程序的执行结果是【 】。 include "stdio h" main() { int a=-1,b=1,k; if((++a<0)&&! (b--<=0)) printf("%d,%d n",a
