A.11月25日
B.11月20日
C.11月30日
D.12月3日
第1题
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
完成以下中序线索化二叉树的算法。
[函数]
Typedef int datatype;
Typedef struct node {
Int ltag, rtag;
Datatype data;
*lchild,* rchild;
}bithptr;
bithptr pre;
void inthread (p );
{if
{inthread (p->lchild );
if (p->lchild==unll ) (1);
if (P->RCHILD=NULL) p->rtag=1;
if (2)
{if (3) pre->rchild=p;
if (p->1tag==1 )(4);
}
INTHREAD (P->RCHILD );
(5);
}
}
第2题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在答题纸的对应栏内。
【函数2.1说明】
递归函数sum(int a[], int n)的返回值是数组a[]的前n个元素之和。
【函数2.1】
int sum (int a[],int n)
{
if(n>0) return (1);
else (2);
}
【函数2.2说明】
有3个整数,设计函数compare(int a,int b,int c)求其中最大的数。
【函数2.2】
int compare (int a, int b, int c )
{ int temp, max;
(3) a:b;
(4) temp:c;
}
【函数2.3说明】
递归函数dec(int a[],int n)判断数组a[]的前n个元素是否是不递增的。不递增返回 1,否则返回0。
【函数2.3】
int dec(int a[], int n )
{
if(n<=1) return 1;
if(a[0]<a[1]) return 0;
return (5);
}
第3题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【说明】
给定函数fun的功能是:将从键盘上输入的每个单词的第一个字母转换为大写字母,输入时各单词必须用空格隔开,用“.”结束输入。
【函数】
int fun(char *c,int status)
{
if((1)=='')
return 1;
else
{
if((2)&&(3)&&(4))
(5)='A'-'a';
return 0;
}
}
main()
{
int flag=1;
char ch;
printf("请输入一字符串,用点号结束输入!\n");
do {
ch=getchar();
flag=fun(&ch,flag);
putchar(ch);
}while(ch!='.');
printf("\n");
}
第4题
阅读下列函数说明和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);
}
第5题
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
编写一个函数,输入为偶数时,调用函数求1/2+?/+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n (利用指针函数)。
[函数]
include "stdio. h",
main()
{
float peven (),podd (),dcall ();
float sum;
int n;
while (1)
{
scanf("%d",&n);
if (n>1)
break;
}
if(n%2==0)
{
printf("Even="):
(1);
}
else
{
pfinff("Odd=");
(2);
}
printf("%f",sum);
}
float peven (int n)
{
float s;
int i
s=1;
for(i=2;i<=n;i+=2)
(3);
return (s);
}
float podd (n)
int n;
{
float s;
int i;
s=0;
for(i=1 i<=n;i+=2)
(4);
return (s);
}
float dcall(fp,n)
float (*fp) ();
int n;
{
float s;
(5);
returu (s);
}
第6题
●试题四
阅读下列函数说明和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) ;
}
第7题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明]
已知r[1...n]是n个记录的递增有序表,用折半查找法查找关键字为k的记录。若查找失败,则输出“failure",函数返回值为0;否则输出“success”,函数返回值为该记录的序号值。
[C函数]
int binary search(struct recordtype r[],int n,keytype k)
{ intmid,low=1,hig=n;
while(low<=hig){
mid=(1);
if(k<r[mid].key) (2);
else if(k==r[mid].key){
printf("succesS\n");
(3);
}
else (4);
}
printf("failure\n");
(5);
}
第8题
阅读以下函数说明和C语言函数,将应填入(n)的字句写在答题纸的对应栏内。
[说明1]
函数int fun1(int m, int n)的功能是:计算并返回正整数m和n的最大公约数。
[函数1]
int fun1(int m, int n)
{
while ((1)) {
if (m>n) m=m-n;
else n=n-m;
}
(2);
}
[说明2]
函数long fun2(char*str)的功能是:自左至右顺序取出非空字符串str中的数字字符形成一个十进制整数(最多8位)。
例如,若字符串str的值为“f3g8d5.ji2e3p12fkp”,则函数返回值为3852312。
[函数2]
long fun2(char *str)
{
int i=0;
long k=0;
char *p=str;
while (*p!='\0' &&(3)) {
if (*p>='0' && *p<='9') {
k=(4)+ *p - '0';
++i;
}
(5);
}
return k;
}
第9题
阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。
【说明】
在下面函数横线处填上适当的字句,使其输出结果为:
构造函数.
构造函数.
1,2
5,6
析构函数
析构函数.
【C++代码】
include "iostream.h"
class AA
{ public;
AA(int i,int j)
{A=i; B=j;
cout<<"构造函数.\n";
}
~AA(){(1);}
void print();
private:
int A, B;
};
void AA∷print()
{cout<<A<<","<<B<<endl;}
void main()
{
AA *a1, *a2;
(2)=new AA(1, 2);
a2=new AA(5, 6);
(3);
a2->print();
(4) a1;
(5) a2;
}
第10题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
[说明1]
本程序输入一字符串,并将其中的大写字母变成小写字母。
[C函数1]
include<stdio.h>
void main()
{ int i=0;
char s[120];
printf("Enter a string.\n");
scanf("%s",s);
while((1) ){
if((2) )
s[i]=s[i]-'A'+'a';
i++;
}
printf("%s\n",S);
}
[说明2]
本程序用二分法,在已按字母次序从小到大排序的字符数组list[len]中,查找字符c,若c在数组中,函数返回字符c在数组中的下标,否则返回-1。
[C函数2]
int search(char list[],char c,int len)
(intlow=0,high=len-1,k;
while((3) );
k=(10w+high)/2;
if((4) ) return k;
else if((5) )high=k-1;
else low=k+1;
return -1;
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!