有以下程序 #include <stdio.h> void fun(int *s,int n1,int n2) { int i,j,t; i=n1 j=n2; while(i<j) {t=s[i];s[i]=s[j];s[j]=t;i++;j--;} } main() { int a[10]={1,2,3,4,5,6,7,8,9,0},k; fun(a,0,3); fun(a,4,9); fun(a,0,9); for(k=0;k<10;k++)printf("%d",a[k]); printf("\n"); } 程序的运行结果是
A.987654321
B.4321098765
C.5678901234
D.987651234
第1题:
有以下程序 #inclUde <stdio.h> void fun(int *s,int n1,int n2) { int i,j,t; i=n1; j=n2; while(i<j) {t=s[i];s[i]=s[j];s[j]=t;i++;j--;} } main() { int a[10]={1,2,3,4,5,6,7,8,9,0},k; fun(a,0,3); fun(a,4
A.0987654321
B.4321098765
C.5678901234
D.0987651234
第2题:
有下列程序: #include <stdio.h> #include "string.h" void tim(char *s[],int n) { char *t;int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(strlen(s[i])>strlen(s[j])) {t=s[i];s[i]=s[j];s[j]=t;} } main() { char *ss[]= {"bcc","bbcc","xy","aaaacc","aabcc"}; fun(ss,5);printf("%s,%s\n",ss[0],ss[4]); } 程序的运行结果是( )。
A.xy,aaaacc
B.aaaacc,xy
C.bcc,aabcc
D.aabcc,bcc
第3题:
有以下程序
#include <stdio.h>
#include <string.h>
void fun(char s[][10],int n)
{ char t;int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
/* 比较字符串的首字符大小,并交换字符串的首字符 */
if (s[i][0] > s[j][0]) {t=s[i][0];s[i][0]=s[j][0];s[j][0]=t;}
}
main()
{ char ss[5][10]={"bcc","bbcc","xy","aaaacc","aabcc"};
fun(ss,5); printf("%s,%s\n",ss[0],ss[4]);
}
程序运行结果是
A)xy,aaaacc
B)aaaacc,xy
C) xcc,aabcc
D) acc,xabcc
第4题:
下列给定程序中,函数fun()的功能是:读入一个字符串 (长度<20),将该字符串中的所有字符按ASCII码降序排序后输出。
例如:输入dafhc,则应输出hfdca。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,敢不得更改程序的结构。
试题程序:
include <conio.h>
include <stdio.h>
/*************found**************/
int fun(char t[])
{
char c;
int i,j;
for(i=0;i<strlen(t)-1;i++)
for(j=i+1;i<strlen(t);j++)
if(t[i]<t[j])
{
c=t[j];
/*************found**************/
t[i]=t[i++];
t[i]=c;
}
}
main()
{
char s[81];
clrscr();
printf("\nPlease enter a character
string:");
gets(s);
printf("\n\nBefore sorting:\n%S",s);
fun(s);
printf("\nAfter sorting decendingly:\n
%s",s);
}
第5题:
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。
【说明】
函数QuickSort是在一维数组A[n]上进行快速排序的递归算法。
【函数】
void QuickSort( int A[ ],int s,int t)
{ int i=s,j=t+1,temp;
int x=A[s];
do{
do i ++ ;while (1);
do j -- ;while(A[j]>x);
if(i<j){temp=A[i];(2);(3);}
}while(i<j);
A[a] =A[j];A[j] =x;
if(s<i-1) (4);
if(j+1<t) (5);
}
第6题:
有以下程序: #include<stdio.h> #include<string.h> void fun(char s[][10],int n) { char t;int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) /*比较字符串的首字符大小,并交换字符串的首字符*/ if(s[i][0]>s[j][0]){t=s[i][0];s[i][0]=s[j][0];sEj][0]=t;} } main() {char s[5][10]={"bcc","bbcc","xy","aaaacc","aabcc"); fun(ss,5);printf("%s,%s\n",ss[0],ss[4]); } 程序的运行结果是( )。
A.xy,aaaacc
B.aaaacc,xy
C.xcc,aabcc
D.acc,xabcc
第7题:
有以下程序
#include <stdio.h>
#include <string.h>
void fun(char *s[],int n)
{ char *t; int i,j;
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strlen(s[i])>strlen(s[j])) {t=s[i];s[i]:s[j];s[j]=t;}
}
main()
{ char *ss[]={"bcc","bbcc","xy","aaaacc","aabcc"};
fun(ss,5); printf("%s,%s\n",ss[0],ss[4]);
}
程序的运行结果是
A.xy,aaaacc
B.aaaacc,xy
C.bcc,aabcc
D.aabcc,bcc
第8题:
有以下程序
#include <stdio.h>
void fun(int *s,int nl,int n2)
{ int i,j,t;
i=nl; j=n2;
while(i<j) {t=s[i];s[i]=s[j];s[j]=t;i++;j--;}
}
main( )
{ int a[10]={1,2,3,4,5,6,7,8,9,0},k;
fun(a,0,3); fun(a,4,9); fun(a,0,9);
for(k=0;k<10;k++)printf("%d",a[k]); printf("\n");
}
程序运行的结果是 ( )
A)0987654321
B)4321098765
C)5678901234
D)0987651234
第9题:
有以下程序: #include <stdio.h> void f(int a[],int i, int j) { int t; if(i<j) { t=a[i];a[i]=a[j];a[j]=t; f(a,i+1,j-1); } } main() { int i,aa[5]={1,2,3,4,5}; f(aa,0,4); for(i=0;i<5;i++) printf("%d,",aa[i]);printf("\n"); } 执行后的输出结果是( )。
A.5,4,3,2,1,
B.5,2,3,4,1,
C.1,2,3,4,5,
D.1,5,4,3,2,
第10题:
以下程序的输出结果是______。
include <stdio.h>
void swap(int *a, int *b)
{ int *t;
}
{ int i=3,j=5,*p=&i,*q=&j;
swap(p,q); printf("%d %d\n",*p,*q);