【填空题】以下程序的运行结果是【1】,其算法是【2】。 main() {int a[5]={9,6,8,3,-1},i,j,t,p; sort(a); for(i=0;i<=4;i++) printf("%3d",a[i]); } sort(int a[]) {int i,j,t,p; for(j=0;j<4;j++) {p=j; for(i=j;i<=4;i++) if(a[i]<a[p]) p=i; t=a[p];a[p]=a[j];a[j]=t; } }

【填空题】以下程序的运行结果是【1】,其算法是【2】。 main() {int a[5]={9,6,8,3,-1},i,j,t,p; sort(a); for(i=0;i<=4;i++) printf("%3d",a[i]); } sort(int a[]) {int i,j,t,p; for(j=0;j<4;j++) {p=j; for(i=j;i<=4;i++) if(a[i]<a[p]) p=i; t=a[p];a[p]=a[j];a[j]=t; } }


参考答案和解析
6

相关考题:

有以下程序#include string.hvoid f(char p[][10], int n ) /* 字符串从小到大排序 */{ char t[10]; int i,j;for(i=0;in-1;i++)for(j=i+1;jn;j++)if(strcmp(p[i],p[j])0) {strcpy(t,p[i]); strcpy(p[i],p[j]); strcpy(p[i],t); }}main( ){ char p[5][10]={"abc", " aabdfg","abbd", " dcdbe","cd"};f(p,5);printf("%d\n",strlen(p[0]));}程序运行后的输出结果是A) 2B) 4C) 6D) 3

有以下程序struct S {int n; int a[20];};void f(struct S *P){ int i,j,t;for(i=0;ip-n-1;i++)for(j=i+1;jp-n;j++)if(p-a[i]p-a[j]) { t=p-a[i]; p-a[i]=p-a[j]; p-a[j]=t; }}main( ){ int i; struct S s={10,{2,3,1,6,8,7,5,4,10,9}};f(s);for(i=0;is.n;i++) printf("%d",s.a[i]);}程序运行后的输出结果是A)1,2,3,4,5,6,7,8,9,10,B)10,9,8,7,6,5,4,3,2,1,C)2,3,1,6,8,7,5,4,10,9,D)10,9,8,7,6,1,2,3,4,5,

有以下程序struct S {int n; int a[20];}; void f(struct S *P) {int i,j,t; for(i=0;in-1;i++) for(j=i+1;jn;j++) if(p-a[i]p-a[j]) { t=p-a[i]; p-a[i]=p-a[j]; p-a[j]=t; } } main() {int i; struct S s={10,{2,3,1,6,8,7,5,4,10,9}}; f(s); for(i=0;i printf(“%d”,s.a[i]); } 程序运行后的输出结果是( )。 A.1,2,3,4,5,6,7,8,9,10,B.10,9,8,7,6,5,4,3,2,1,C.2,3,1,6,8,7,5,4,10,9,D.10,9,8,7,6,1,2,3,4,5,

有以下程序 include void f(char p[][10],int n)/*字符串从小到大排序*/ { 有以下程序 #include<string.h> void f(char p[][10],int n)/*字符串从小到大排序*/ { char t[10];int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strcmp(p[i],p[j])>0) {strcpy(t,p[i]);strcpy(p[i],p[j]);strcpy(p[j],t);} } main() { char p[5][10]={"abc","aabdfg:,"abbd","dcdbe","cd"}; f(p,5); printf("%d\n",strlen(p[0])); } 程序运行后的输出结果是A.2B.4C.6D.3

有以下程序 struct S{ int n;int a[20];}; voidf(struct S*p) { int i,j,t; for(i=0;i<p->n-1;i++) for(j=i+1;j<p->n;j++) if(p->a[i]>p->a[j]){t=p->a[i];p->a[i]=p->a[j];p->a[j]=t;} } main() { int i;struct S s={10,{2,3,l,6,8,7,5,4,10,9}}; f(s); for(i=0;i<s.n;i++)printf("%d,",s.a[i]); } 程序运行后的输出结果是A.1,2,3,4,5,6,7,8,9,10,B.10,9,8,7,6,5,4,3,2,1,C.2,3,1,6,8,7,5,4,10,9,D.10,9,8,7,6,1,2,3,4,5,

有以下程序,其中函数的功能是将多个字符串按字典顺序排序: includevoid f(char*p[],i 有以下程序,其中函数的功能是将多个字符串按字典顺序排序: # include<string.h> void f(char*p[],int n) {char *t; int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strcmp(p[i],p[j])>0){t=p[i];p[i]=p[j]p[j]=t;} } main() {char *p[5]={"abc","aabdfg","abbd","dcdbe","cd"}; f(p,5); printf("%d\n",strlen(p[1])); } 程序运行后的输出结果是 ______。A.2B.3C.6D.4

有以下程序:includevoid f(char p[][10],int n)/* 字符串从小到大排序*/{char t[10]; 有以下程序: #include<string.h> void f(char p[][10],int n) /* 字符串从小到大排序 */ {char t[10];int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strcmp(p[i],p[j])>0{strcpy(t,p[i]);strcpy(p[i],p[j]);strcpy([i],t);} } main() {char p[5][10]={"abc","aabdfg","abbd","dcdbe","cd"; f(p,5); printf("%d\n",strlen(p[0])); } 程序运行后的输出结果( )。A.2B.4C.6D.3

下面程序的功能是:对字符串从小到大进行排序并输出,请填空。#include "string.h"#include "stdio.h"sort(char *a[],int n){ int i,j;char *p;for(j=1;j=n-1;j++)for(i=0; 【15】 ;i++)if( 【16】 0){ p=a[i];a[i]=a[i+1];a[i+1]=p;}}main(){ int i;char *book[]={"itisme","itisyou","howareyou","fine","goodnight","goodbye"};sort( 【17】 );for(i=0;i6;i++)printf("%s\n",book[i]);}

有以下程序: include usingnamespacestd; intmain() { intnum[2][3],*p; intt,i,j,k= 有以下程序: #include <iostream> using namespace std; int main() { int num[2][3],*p; int t,i,j,k=10; p=num[0]; for(i=0;i<2;i++) { for(j=0;j<3;j++) { k++; *p=k; for(t=2;t<*p;t++) { if(!(*p%t)) { j--; *p--; break; } *p++; } } cout<<*(p-1)<<end1; return 0; } 程序运行后的输出结果是( )。A.19B.11C.29D.23

有以下程序struct STU{ char name[10]; int num; int Score;};main(){ struct STU s[5]={{"YangSan",20041,703}, {"LiSiGuo",20042,580}, {"WangYin",20043,680}, {"SunDan",20044,550}, {"Penghua",20045,537}}, *p[5], *t; int i,j; for(i=0;i5;i++) p[i]=s[i]; for(i=0;i4;i++) for(j=i+1;j5;j++) if(p[i]-Scorep[j]-Score) { t=p[i]; p[i]=p[j]; p[j]=t; } printf("%d %d\n",s[1].Score,p[1]-Score);}程序运行后的输出结果是A.550 550 B.580 550 C.680 680 D.580 680

有以下程序:includevoid f(char p[][10],int n){char t[10];int i,j;for(i=0;i 有以下程序: #include<string.h> void f(char p[][10],int n) {char t[10];int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strcmp(p[i],p[j])>0) {strcpy(t,p[i]);strcpy(p[i],p[j]);strcpy(p[j],t);} } main() {char p[5][10]={"abc","aabdfg","abbd","dedbe","cd"}; f(p,5); printf("%d\n",strlen(p[0]));} 程序运行后的输出结果是( )。A.2B.4C.6D.3

以下程序输出正确的是_______ amovep(int *p,int (*a)[3],int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++){ *p=a[i][j];p++;} } main() {int *p,a[3][3]={{1,3,5}, {2,4,6}}; p=(int*)mallox(100) amovep)p,a,3); printf("%d%d\n",p[2],p[5]);free(p) }A.56B.25C.34D.程序错误

有以下程序,其中函数f的功能是将多个字符串按字典顺序排序( )。 #includestring.h void f(char*p[],int n) { char*t;int i,j; for(i=0;in-1;i++) for(j=i+1;jn;j++) if(strcmp(p[i],p[j]0){t=p[i];p[i]=p[j];p[j] =t;} } main { char *P[5]={"abe","aabdfg","abbd","dcd- be","cd"}; f(p,5); printf("%d\n",strlen(p[1])); } 程序运行后的输出结果是( )oA.2B.3C.6D.4

有以下程序: struct STU { char name[10]; int num; int score; }; main() { struct STU s[5]={{"YangSan",20041,703},{"LiSiGuo",20042,580}, {"WangYin",20043,680},{"SunDan",20044,550), {'Penghua",20045,537}},*p[5],*t; int i,j; for(i=0;i<5;i++) p[i]=s[i]; for(i=0;i<4;i++) for(j=i+1;j<5;j++) if(p[i]->Score>p[j]->Score) { t=p[i];p[i]=p[j];p[i]=t; } printf("%d %d\n",s[1].Score,p[1]->Score); } 执行后输出结果是( )。A.550 550B.680 680C.580 550D.580 680

下列程序运行后,输出结果是______。main(){ char ch[2][5]={"693","825"),*p[2]; int i,j,s=0; for (i=0;i<2;i++) p[i]=ch[i]; for (i=0;i<2;i++) for (j=0;p[i][j]>='0' p[i][j]<='9';j+=2) s=10*s+p[i][j]-'0'; printf("%d\n",s);}A.6385B.22C.33D.693825

下面程序的输出结果是______。 main() { int a[3][4]={1,3,5,7,9,11,13,15,17,19,21,23}; int(*p)[4]=a,i,j,k=0; for(i=0;i<3;i++) for(j=0;j<2;j++) k=p[i][j]; printf("%d\n",k); }A.17B.18C.19D.23

有以下程序 struct STU { char name[10];v int num; int Score; }; main( ) { struct STU s[5]={ {“YangSan”,20041,703},{“LiSiGuo”,20042,580}, {“wangYin”,20043,680},{“SunDan”,20044,550}, {“Penghua”,20045,537}},*p[5],*t; int i,j; for(i=0;i<5;i++) p[i]=s[i]; for(i=0;i<4;i++) for(j=i+1;j5;j++) if(p[i]->Scorep[j]->Score) { t=p[i];p[i]=p[j];p[j]=t;} printf(“%d %d\n”,s[1].Score,p[1]->Score); } 执行后输出结果是( )A.550 550B.680 680C.580 550D.580 680

有以下程序,其中函数f的功能是将多个字符串按字典顺序排序:includevoidf(char*p[],in 有以下程序,其中函数f的功能是将多个字符串按字典顺序排序: #include<string.h> voidf(char*p[],intn) { char*t;int i,j; for(i=0;i<n-1;i++) for (j=i+1;j<n;j++) if(strcmp(p[i],p[j])>0) { t=p[i]; p[i]=p[j]; p[j]=t; } } main() { char*p[5]={"abc"A.2B.3C.6D.4

以下程序输出正确的是______。 amovep(int *pint(*a) [3]int n) { int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++){ *p=a[i][j];p++;} } main() {int *p,a[3][3]={{1,3,5},{2,4,6}}; p=(int*)malloc (100); amovep(p,a,3); printf("%d%d\n",p[2]p[5];free(p); }A.56B.25C.34D.程序错误

有以下程序:struct S{int n;int a[20];};void f(struct S*P){int i,j,t;for(i=0;in-1;i++)fo 有以下程序: struct S{int n;int a[20];}; void f(struct S*P) { int i,j,t; for(i=0;i<P->n-1;i++) for(j=j+1;j<P->n-1;j++) if(p->a[i]>p->a[j]) {t=P->a[i];p->a[i]=P->a[j];p->a[j]=t} } main() {int i;struct S s{10,{2,3,1,6,8,7,5,4,10,9}}; f(&s); for(i=0;i<s.n;i++)printf("%d",s.a[i]);} 程序运行后的输出结果是( )。A.3B.4C.5D.6

以下程序运行后,输出结果是______。 main() {char ch[2][5]={"693","825"},*p[2]; int i,j,s=0; for(i=0;i<2;i++)p[i]=ch[i]; for(i=0;i<2;i++) for(j=0;p[i][j]>='0'p[i][j]<='9';j+=2) s=10*s+p[i][j]-'0'; printf("%d\n",s); }A.6385B.22C.33D.693825

有以下程序:include struct STU{char name[10]; int num; int Score;};main(){struct 有以下程序: #include <stdio.h> struct STU { char name[10]; int num; int Score; }; main() { struct STU s[5]={{"YangSan",20041,703},{"LiSiGuo",20042,580}, {"WangYin",20043,680},{"SunDan",20044,550}, {"Penghua",20045,537}}, *p[5],*t; int i,j; for(i=0;i<5;i++) p[i]=s[i]; for(i=0;i<4;i++) for(j=i+1;j<5;j++) if(p[i]->Score>p[j]->Score) { t=p[i];p[i]=p[j];p[j]=t;} printf("%d%d\n",s[1].Score,p[1]->Score); } 执行后的输出结果是( )。A.550 550B.680 680C.580 550D.580 680

有以下程序 struet STU { char name[10]; int num; int Score; }; main() { struct STU s[5]-{{"YangSan",20041,703},("LiSiGuo",20042,580}, {"WangYin",20043,680},{"SunDan",20044,550}, {"Penghua",20045,537}},*p[5],*t; int i,j; for(i=0;i<5;i++) p[i]-s[i]; for(i 0;i<4;i++) for(j-i+1;j<5;j++) if(p[i] >Score>p[j] >Score) { t=p[i];p[i]=p[j];p[j]-t;} printf("%d %dkn",s[1].Score,p[1]->Score); } 执行后输出结果是A.550 550B.680 680C.580 550D.580 680

有以下程序,其中函数f的功能是将多个字符串按字典顺序排序includevoid f(char*p[],in 有以下程序,其中函数f的功能是将多个字符串按字典顺序排序 #include <string,h> void f(char *p[], int n) { char *t; int i,j; for(i=0; i<n-1; i++) for(j=i+1;j<n; j++) if(strcmp(p[i],p[j])>0) {t=p[i];p[i]=p[j]; p[j]=t;} } main() { char *p[5]={"abc","aabdfg","abbd","dcdbe","cd"}; f(p,5); printf("%d\n"。strlen(p[1])); } 程序运行后的输出结果是A.2B.3C.6D.4

有以下程序 struct STU { char name[10]; int num; int Score; { main() { struct Stu s[5]={{"YangSan",20041,703},{"LiSiGuo",20042,580}, {"WangYin",20043,680},{"SunDan",20044,550}, {"Penghua",20045;537}},*p[5],*t; int i,j; for(i=0;i<5;i++)p[i]=s[i]; for(i=0;i<4;i++) for(j=i+1;j<5;j++) if(p[i]->Score>p[j]->Score) {t=p[i];p[i]=p[j];p[i]=t;} printf("%d%d\n",s[1].Score,p[1]->Score); } 执行后输出结果是A.550550B.680680C.580550D.580680

有以下程序:include void f(char p[][10],int n)/* 字符串从小到大排序 */{ char t[1 有以下程序: #include <string.h> void f(char p[][10],int n)/* 字符串从小到大排序 */ { char t[10]; int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strcmp(p[i],p[j])>0) { strcpy(t,p[i]); strcpy(p[i],p[j]); strcpy(p[j],t); } } main() {char p[5][10]={"abc","aabdog","abbd","dcdbe","cd"}; f(p,5); printf("%d\n",strlen(p[0])); } 程序运行后的输出结果是( )。A.2B.4C.6D.3

单选题以下选项中,不能对主函数中变量i和j的值进行交换的程序是(  )。A#include stdio.hvoid swap(int *p, int *q){ int *t; *t = *p; *p = *q; *q = *t;}main(){ int i=10, j=20,*a=i,*b=j; swap(a,b); printf(i=%d j=%d,i,j);}B#include stdio.hvoid swap(int *p, int *q){ int t; t = *p; *p = *q; *q = t;}main(){ int i=10,j=20,*a=i,*b=j; swap(a,b); printf(i=%d j=%d,i,j);}C#include stdio.h#include stdlib.hvoid swap(int *p, int *q){ int *t; t = (int *)malloc(sizeof(int)); *t = *p; *p = *q; *q = *t; free(t);}main(){ int i=10,j=20; swap(i,j); printf(i=%d j=%d,i,j);}D#include stdio.hvoid swap( int *p, int *q){ int t; t = *p; *p = *q; *q = t;}main(){ int i=10,j=20,*x=i,*y=j; swap(x,y); printf(i=%d j=%d,i,j);}

单选题有以下程序#include struct S{ int n; int a[20];};void f(struct S *p){ int i,j,t; for(i=0;in-1;i++)  for(j=i+1;jn;j++)   if(p-a[i]p-a[j])   {    t=p-a[i];    p-a[i]=p-a[j];    p-a[j]=t;   }}main(){ int i; struct S s = {10,{2,3,1,6,8,7,5,4,10,9}}; f(s); for(i=0;iA1,2,3,4,5,6,7,8,9,10,B10,9,8,7,6,5,4,3,2,1,C2,3,1,6,8,7,5,4,10,9,D10,9,8,7,6,1,2,3,4,5,