题目
阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。
[函数2.1说明]
下面程序的功能是计算x和y的最小公倍数。
[函数2.1]
main()
{ int m,n,d,r;
seanf("%d %d",&m,&n);
if(m<n) {r=m;m=n;n=r;}
(1);
while (d%n! =0) (2);
printf("%d\n",d);
}
[函数2.2说明]
下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。
[函数2.2]
include <stdio.h>
main()
{ char c,preChar='\0';
c = getchar();
while(c! = '.'){
if((3)) putchar(c);
else if(preChar! =' ') putchar(c);
(4);
c=(5);
}
}
第1题
●试题二
阅读下列函数说明和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");
}
}
第2题
试题三(共 15 分)
阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。
第3题
阅读下列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));
}
}
第4题
第5题
阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。
【说明】清点盒子。本程序当用户输入一个整数值时,一切正常;当输入其他数值时,程序就出错。现在已做了改进,请填空。
import java. text. NumberFormat;
Public class InventoryLoop
{
public static void main(String args[])
{
String numBoxesIn;
Int numBoxes;
Double boxPrice=3.25;
Boolean gotGoodInput=false;
NumberFormat currency=NumberFormat.(1);
do
{
System.out. print(“How many boxes do we have?”);
numBoxesIn=DummiesIO. (2);
try
{
numBoxes=Integer.parseInt((3));
system. out. print("The value is");
system.out. println(currency, format (numBoxes*boxPrice));
gotGoodInput=true;
catch((4))
{
System.out.println();
System.out. println(That's not a number.");
}
}while((5));//输入不正确时
System. out.println("That's that.");
}
}
第6题
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。
【说明】
以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。
【程序】
include < stdio. h >
main()
{ FILE * fp;
char str[100]; int i=0;
if((fp=fopen("text.txt"(1))) ==NULL)
{ printf("can't open this file. \n") ;exit(0) ;}
printf(" input astring: \n" ); gest(str);
while(str[i] )
{ if(str[i] >='a' && str[i] <='z')
str[i]=(2);
fputc(str[i],(3));
i++;
}
fclose(fp);
fp=fopen(" test.txt",(4));
fgets(str, 100, fp);
printf("%s\n" ,str);
(5);
}
第7题
阅读下列程序说明和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);
}
第8题
阅读下列程序说明和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;
}
}
第9题
●试题八
阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。
【说明】
以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。
【程序】
#include<stdio.h>
main()
{FILE*fp;
charstr[100];inti=0;
if((fp=fopen("text.txt" (1) ))==NULL)
{printf("can't open this file.\n");exit(0);}
printf("input astring:\n");gest(str);
while(str[i])
{if(str[i]>=′a′ && str[i]<=′z′)
str[i]= (2) ;
fputc(str[i], (3) );
i++;
}
fclose(fp);
fp=fopen("test.txt", (4) );
fgets(str,100,fp);
printf("%s\n",str);
(5) ;
}
第10题
●试题二
阅读下列程序或函数说明和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);
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!