第一范文网 - 专业文章范例文档资料分享平台

浙江省高等学校二级C语言(笔试部分真题2008-2010年)

来源:用户分享 时间:2025/5/15 19:52:01 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

【程序说明】

验证哥德巴赫猜想:任何一个大于6的偶数均可表示为两个素数之和。例如6=3+3,8=3+5,…,18=7+11。将6~20之间的偶数表示成两个素数之和,打印时一行打印5组。要求定义和调用函数prime(m)判断m是否为素数,当m为素数时返回1,否则返回0。素数就是只能被1和自身整除的正整数,1不是素数,2是素数。

运行示例:

6=3+3,8=3+5,10=3+7,12=5+7,14=3+11 16=3+13 18=5+13 20=3+17 18=7+11 【程序】

#include #include int prime(int m) { int i, n;

if(m == 1) return 0; n = sqrt(m);

for(i = 2; i <= n; i++) if(m % i == 0) return 0 (5)

}

main()

{ int count, i,number; count=0;

for(number=6;number<=20;number=number+2){ for(i=3;i<=number/2;i=i+2) if(__(6)_____){

printf(“%d=%d+%d”,number,i,number – i); count++;

if(__(7)_____) printf(“\\n”); ( (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中数字字符、英文字母和其它字符的

17

个数,函数形参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分)

阅读下列程序并回答问题,在每小题提供的若干可选答案中,挑选一个正确答案。

【程序】

18

#include main()

{ 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); }

19

}

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 main()

{ 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

20

浙江省高等学校二级C语言(笔试部分真题2008-2010年).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1bu5h3ccg28ojis8frd8_5.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top