( (8) ) } } }
【供选择的答案】
(5) A、; B、return 1;
C、return 0; D、else return 1; (6) A、prime(i)!=0 || prime(number – i)!=0 B、prime(i)!=0 && prime(number – i)!=0
C、prime(i)==0 || prime(number – i)==0
D、prime(i)==0 && prime(number – i)==0 (7) A、count % 5 ==0 B、count % 5!=0 C、(count+1)%5==0 D、(count+1)%5!=0 (8) A、break; B、else break; C、continue; D、; 试题3(每小题3分,共12分)
阅读下列程序说明和程序,在每小题提供的若干可选答案中,挑选一个正确答案。 【程序说明】
输入一行字符,统计并输出其中数字字符、英文字母和其他字符的个数。要求定义并调用函数count(s, digit,letter,other)分类统计字符串s中数字字符、英文字母和其它字符的个数,函数形参s的类型是字符指针,形参digit,letter,other的类型是整形指针,函数类型是void。
运行示例:
Enter characters:f(x,y)=5x+2y-6 Digit=3 letter=5 other=6 【程序】
#include
void count (char *s, int * digit, int * letter, int * other) { _____(9)___ while(_____(10)___){
if (*s>=?0? && *s<=?9?) (*digit)++;
else if ((*s>=?a? && *s<=?z?)||(*s>=?A? && *s<=?z?)) (*letter)++; else
(*other)++; s++; } }
main() { int i=0,digit,letter,other; char ch,str[80];
printf(“Enter characters:”); ch=getchar();
while (____(11)___){ str[i]=ch; i++;
ch=getchar();
}
str(i)=?\\0?; ___(12)__;
Printf(“digit=&d letter=%d other=%d\\n”, digit,letter,other); }
【供选择的答案】
(9) A、int dight=0,letter=0,other=0;
B、int *dight=0,*letter=0,*other=0; C、dight=letter=other=0;
D、*dight=*letter=*other=0; (10) A、*s++ !=?\\0 ? B、*s++ !=?\\n? C、*s!=?\\0? D、 *s !=?\\n? (11) A、ch !=?\\0? B、ch !=?\\n? C、ch ==?\\0? D、ch ==?\\n?
(12) A、count(str,&digit,&letter,&other)
B、count(&str,&digit,&letter,&other)
C、count(*str, digit, letter,other)
D、count(*str,*digit,*letter,*other)
试题4(每小题3分,共12分)
阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。
【程序】
#include
{ int flag=0,i;
int a[7]={8,9,7,9,8,9,7};
for(i=0;i<7;i++) if(a[i]==7){ flag=i
break; }
printf(“%d\\n”,flag); flag=-1
for(i=6;i>=0;i--) if(a[i]==8){ break; flag=i; }
printf(“%d\\n”,flag); flag=0;
for(i=0;i<7;i++) if(a[i]==9){
printf(“%d”,i); }
printf(“\\n”); flag=0;
for(i=0;i<7;i++)
if(a[i]==7) flag=i; printf(“%d\\n, flag”);
}
(13) 程序运行时,第1行输出 (13) 。
A、2 B、0 C、3 D、6 (14) 程序运行时,第2行输出 (14) 。
A、4 B、-1 C、0 D、5 (15) 程序运行时,第3行输出 (15) 。
A、2 4 6 B、4 C、1 3 5 D、6 (16) 程序运行时,第4行输出 (16) 。
A、2 4 6 B、2 C、1 3 5 D、6 试题5(每小题3分,共12分)
阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。
【程序】
int f1(int n)
{ if(n==1) return 1 ;
else return f1(n-1) + n; }
int f2(int n) { switch(n){ case 1:
case 2:return 1;
default: return f2(n-1) + f2(n-2); } }
void f3(int n)
{ printf(“%d”,n);
if(n/10 !=0) f3(n/10); }
void f4(int n)
{ if (n/10 !=0) f4(n/10); printf(“%d”, n); }
#include
{ printf(“%d\\n”,f1(4)); printf(“%d\\n”,f2(4)); f3(123);
printf(“\\n”); f4(123);
printf(“\\n”); }
(17) 程序运行时,第1行输出 (17) 。 A、10 B、24 C、6 D、1 (18) 程序运行时,第2行输出 (18) 。
A、1 B、3 C、2 D、4 (19) 程序运行时,第3行输出 (19) 。
A、123 B、3 C、321 D、1 (20) 程序运行时,第4行输出 (20) 。
A、1 B、123 C、3 D、321 试题6(每小题3分,共12分)
#include
struct num{ int a,b;};
void f(struct num s[], int n) { int index, j, k; struct num temp;
for(k=0;k< n-1;k++){ index=k;
for(j=k+1;j if(s[j].b main() { int count, i, k, m, n, no; struct num s[100],*p; scanf(“%d%d%d”, &n, &m, &k); for(i=0;i count = no =0; while(no if(p->b==0) count++; if(count==m){ no++; p->b=no; count=0; } p++; if(p==s + n) p=s; } f(s,n); printf(“%d: %d\\n”, s[k-1].b, s[k-1].a); } (21) 程序运行时,输入5 4 3,输出 (21) 。 A、3: 5 B、2: 3 C、1: 2 D、4: 1 (22) 程序运行时,输入5 3 4,输出 (22) 。 A、3: 5 B、1: 2 C、4: 3 D、4: 2 (23) 程序运行时,输入7 5 2,输出 (23) 。 A、1: 5 B、6: 1 C、2: 3 D、2: 4 (24) 程序运行时,输入4 2 4#,输出 (24) 。 A、3: 3 B、4: 2 C、2: 4 D、4: 1 试题7 (28分) (1) 定义函数fact(n)计算n的阶乘:n!=1*2*??*n,函数形参n的类型是 int, 函数类型是double。 (2) 定义函数cal(x, e)计算下列算式的值,直到最后一项的值小于e,函数形 参x和e的类型都是double,函数类型是double。要求调用自定义函数fact(n)计算n的阶乘,调用库函数pow(x, n)计算x的n次幂。 S=x+x^2/2!+x^3/3!+x^4/4!+…… (3) 定义函数main(),输入两个浮点数x和e,计算并输出下列算式的值,直到 最到最后一项的值小于精度e。要求调用自定义函数cal(x,e)计算下列算式的值。 S=x+x^2/2!+x^3/3!+x^4/4!+……