A.1
B.2
C.3
D.5
第1题
阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。
【说明】
阅读下面几段C++程序回答相应问题。
比较下面两段程序的优缺点。
①for (i=0; i<N; i++ )
{
if (condition)
//DoSomething
…
else
//DoOtherthing
…
}
②if (condition) {
for (i =0; i<N; i++ )
//DoSomething
}else {
for (i=0; i <N; i++ )
//DoOtherthing
…
}
第2题
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第3题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【程序2.1说明】
求所有满足如下条件的三位数:它除以11得的商等于它各位数字的平方和。例如 550,除以11商为50,50=52+52+02。
【程序2.1】
void main()
{
int i, j,n,s;
for(i=100;i<=999;i++)
{
n=i;
j=n/11;
s=0;
while((1))
{
(2)
n/=10;
}
if((3))
printf("%d\t",i);
}
}
【程序2.2说明】
本程序输入一字符串,将其中的大写字母改变成小写字母。
【程序2.2】
void main()
{
int i=0;
char s[120];
scanf("%s",s);
while((4))
{
if((5))
s[i]=s[i]- 'A'+'a';
i++;
}
printf("%s\n",s);
}
第4题
●试题二
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
该程序运行后,输出下面的数字金字塔
【程序】
include<stdio.h>
main ()
{char max,next;
int i;
for(max=′1′;max<=′9′;max++)
{for(i=1;i<=20- (1) ;++i)
printf(" ");
for(next= (2) ;next<= (3) ;next++)
printf("%c",next);
for(next= (4) ;next>= (5) ;next--)
printf("%c",next);
printf("\n");
}
}
第5题
阅读下列程序说明和c代码,将应填入(n)处的字句写在对应栏内。
[说明]
下面的程序利用递归算法计算x和y的最大公约数。
[函数2.1]
main ()
{ int x,y,k,t;
scanf(" % d% d" , &x, &y);
if(x>y) { t=x;x=y; y=t;}
(1);
while(k! =0){
y=x;
(2);
k=y%x;
}
prinff("% d" ,x); }
[函数2.2说明]
函数fun(char *str,char *substr的功能是计算子串sugbstr在串str中出现的次数。
[函数2.2]
fun(ehar * str, char * substr)
{ int x,y,z;
(3);
for(x=0;str[ x] ! = '\O';x + + )
for(y=x,z=0;sabstr[z] = =str[y];(4),y+ +)
if((5)= ='\0') {
num + +;
break;
}
return(num);
}
第6题
阅读下列程序说明和C代码,将应填入(n)处的字句写在对应栏内。
[说明]
函数Printprime(int UpBound)的功能是输出1到UpBound以内的全体素数。
[函数2.1]
void PrintPrime(int UpBound)
printf("2," );
for(i=3; i<UpBound; i+ =2) {
int k = sqrt(i);
for(j=3; j<= k;(1)) /*检查i是否有3到k以入的奇因数*/
if((2)) break;
fi((3)) printf("%d", i);
[函数2.2说明]
递归函数invert(int a[],int k),int k)的功能是将数组a中的前k个元素逆置。
[函数2.2]
void invert(int a[ ], int k)
{ int t;
if ((4)) {
invert((5));
t=a[0];
a[0] =a[k-1];
a[k-l]=t;
}
}
第7题
阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。
【说明】StringEditor类的功能是:已知一个字符串,返回将字符串中的非字母字符都删除后的字符串。
public (1) {
public static String removeNonLetters((2) ){
StringBuffer aBuffer=(3);
char aCharacter;
for(int i=0; i<original.length();i++){
aCharacter=(4);
if(Character.isLetter(aCharacter))
aBuffer.append((5) );
}
return new String(aBuffer);
}
}
public class StringEditorTester{
public static void main(String args[]){
String riginal="Hi!, My Name is Mark, 234I think you are my classmate?!!";
System.out.println(StringEditor.removeNonLetters(original));
}
}
第8题
阅读下列函数说明和C函数,将应填入(n)处的字句写在对应栏内。
[函数2.1说明]
Fibonacci数列中头两个数均为1,从第三个数开始,每个数等于前两个数之和。下述程序计算Fibonacci数列中前15个数,并以每行5个数的格式输出。
[函数2.1]
include <stdio.h>
main()
{ int i,f,f1=1,f2=1;
printf("%5d%5d",f1,f2);
for(i=3;i<=15;i++){
f=(1);
printf("%5d",f);
if((2)= =0) printf("\n");
f1=12;
(3);
}
}
[函数2.2说明]
函数fun(char *str1,char *str2)的功能是将字符串str2拼接到str1之后。
[函数2.2]
fun(char *str1,char *str2)
{ int i,j;
for(i=0;str1[i]!='\0';i++);
for(j=0;str2[j]!='\0';j++) (4);
(5);
}
第9题
●试题二
阅读下列程序或函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【函数2.1说明】
函数strcmp()是比较两个字符串s和t的大小。若s<t函数返回负数;若s=t函数返回0;若s>t,函数返回正数。
【函数2.1】
int strcmp(char *s,char *t)
{ while(*s && *t && (1) ){
s++;t++;
}
return (2) ;
}
【程序2.2说明】
在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个。
【程序2.2】
#includestdio.h
#define N 100
int a[N][N];
void main()
{ int row ,col,max,min,n;
/*输入合法n(<100),和输入n×n个整数到数组a的代码略*/
for (row=0;row<n;row++){
for(max=a[row][0],col=1;col<n;col++)
if((3) )max=a[row][col];
if((4) )min=max;
else if((5) )min=max;
}
printf ("The min of max numbers is %d\n",min);
}
第10题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。
【程序2.1说明】
已知一个排好序的数组,现输入一个数,要求按原来的顺序规律,将它插入到数组中。
【程序2.1】
include <stdioh>
define N 100
void main()
{
float a[N+l],x;
int i,p;
printf("输入已经排好序的数列: ");
for(i=0; i<N; i++)
scanf(%f",&a[i]);
printf("输入要插入的数:");
scanf("%f",&x);
for(i=0,p=N; i<N; i++)
if(x<a[i])
{
(1)
break;
}
for(i=N-1; i>=p; i--)
(2)
(3)
for(i=0; i<=N; i++)
prinff("%f\t",a[i]);
}
【程序2.2说明】
本程序用变量count统计文件中字符的个数。
【程序2.2】
include <stdio.h>
include <stdlib.h>
void main()
{
FILE *fp;
long count=0;
if((fp=fopen("letter.txt","r"))==NULL)
{
printf("can not open file\n");
exit(0);
}
while(!feof(fp))
{
(4)
count++;
}
printf("count=%d\n",count);
(5)
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!