题目
A.1
B.2
C.3
D.4
第1题
下列给定程序中,函数fun()的功能是:从N个字符串中找出最长的那个中,并将其地址作为函数值返回。各字符串在主函数中输入,并放入一个字符串数组中。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <string.h>
include <stdio.h>
define N 5
define M 81
/*************found**************/
fun(char (*sq) [N])
{int i; char *sp;
sp=sq[0];
for{i=0;i<N;i++)
if(strlen(sp)<strlen(sq[i]))
sp=sq[i];
/*************found**************/
return sq;
}
main ()
{char str[N][M], *longest; int i;
printf("Enter %d lines:\n ",N);
for(i=0;i<N;i++) gets(str[i]);
printf("\nThe %d string :\n ",N);
for(i=0;i<N;i++) puts(str[i]);
longest=fun(str);
printf("\nThe longest string :\n ");
puts(longest);
}
第2题
例如,形参s所指的字符串为:This is a C languageprogram.,函数的返回值为6。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANKl.C中。
不得增行或删行,也不得更改程序的结构!
第4题
下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是()。 publicclassFindKeyWords{ publicstaticvoidmain(sring[]args){ stingtext= “Anarrayisadatastructurthatstoresacollectionof” +“valuesofthesametype.YOUaccesseachindividualvalue'’ +“throughanintegerindex.Forexample,ifaiSanarray” +“of inergers,thena[i]iSthe ith integer in thearray.”; In tarrayCount=0; Intidex=-1; Sting arrarStr=“array”; IndeX=text.indexof(arrayStr); While(index______0){ ++arrayCount; Index+=arrayStr.length(); IndeX=text.indexof(arrayStr,indeX); } SyStem.out.phntln (“thetextcontains”+arrayCount+“arrays”); } }
A.<
B.=
C.<=
D.>=
第5题
第6题
下列给定程序中,函数fun()的功能是:统计字符串substr在字符串srt中出现的次数。例如,若字符串为aaas 1 kaaas,子字符串为as,则应输出2。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include <stdio.h>
fun (char *str, char *substr)
{int i, j, k, num=0;
/*************found**************/
for (i=0, str [i], i++)
for (j=i, k=O; substr [k]==str [ j ]; k++, j ++ )
if (substr [k+l]==' \0')
{num++;
break;
}
return num;
}
main ()
{ char str[80],substr[80];
printf("Input a string: ");
gets (str);
printf("Input a sbustring: ");
gets (substr);
printf ("%d\n ", fun (str, substr) );
第7题
第8题
下列程序的功能是统计一个字符串中包括多少个汉字(假设这些汉字均属于GB2312字符集),其基本算法是从字符串中依次取一个字符,如果其ASCII码值大于127,则为一个汉字内码的第一个字节。请填空。
STR1="中国(ChinA) 是一个伟大的国家(nation)"
C=0
DO WHILE LEN(STR1)>0
IF _________ (LEFT(STR1,1))>127
C=C+1
STR1=SUBSTR(STR1, ________ )
ELSE
STR1=SUBSTR(STR1, _______ )
ENDIF
ENDDO
WAIT WINDOWS"汉字个数为"+STR(C)
第9题
(30 )下列程序的功能是统计字符串中 “ array ” 的个数,在程序的空白处应填入的正确选项是
public class FindKey Word s{
public static void main(sring[] args){
sting text=
“ An array is a data structur that stores a collection of ”
+ “ values of the same type . You access each individual value ”
+ “ through an integer index . For example,if a is an array ”
+ “ of inergers, then a[i] is the ith integer in the array. ” ;
Int arrayCount =0;
Int idex = -1;
Sting arrarStr = ” array ” ;
Index = text.indexof(arrayStr);
While(index______ 0) {
++arrayCount;
Index += arrayStr.length();
Index = text.indexof(arrayStr,index);
}
System.out.println
(“ the text contains ” + arrayCount + “ arrays ” );
}
}
A) <
B) =
C) <=
D) >=
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!