教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 幼儿教育 >

浙江大学c程2002B试卷E(2)

来源:网络收集 时间:2026-05-01
导读: ch1=fgetc(f1); ch2=fgetc(f2); if(ch1!=ch2){ printf(%c#%c#,ch1,ch2); printf(%d#, count); break; } if(ch1=='?') count++; } fclose(f1); fclose(f2); } 《C Programming》TEST PAPER, June 20, 2003 6 /8 浙江

ch1=fgetc(f1);

ch2=fgetc(f2);

if(ch1!=ch2){

printf("%c#%c#",ch1,ch2);

printf("%d#", count);

break;

}

if(ch1=='?') count++;

}

fclose(f1);

fclose(f2);

}

《C Programming》TEST PAPER, June 20, 2003 6 /8

浙江大学c程2002B试卷E

Section 4: According to the specification, complete each program (2 mark for each blank, total: 30 marks)

1.If input is n(n>0), calculate the value of s = 1/1! + 1/2! + 1/3! + ……+ 1/n!.

#include <stdio.h>

void main( )

{ int j, k, n;

float f, s;

scanf("%d", &n);

;

for (k=1 ; k<=n; k++){

;

; j++)

;

s=s+1.0/f;

}

printf("sum=%f\", s);

}

(1) s=0

(2) f=1

(3) j<=k

(4)f=f*j

2.When input is n (n>0), if it’s a prime number, print "YES", otherwise print "NO". (Prime numbers: an integral number not divisible without a remainder by any integral number other than itself and one. One isn’t a prime number, but two is a prime number)。

#include <stdio.h>

#include <math.h>

void main( )

{

int n;

int prime(int m);

scanf("%d", &n);

)

printf("YES\n");

else

printf("NO\n");

}

《C Programming》TEST PAPER, June 20, 2003 7 /8

浙江大学c程2002B试卷E

int prime(int m)

{ int i,n;

if(m==1) return 0;

n=sqrt(m);

for(i=2; i<=n; i++)

;

;

}

(5) prime(n)

(6) m%i==0

(7) 0

(8)return 1

3.The definition of function f2 () is equivalent to the definition of function f1 ().

int f1(char s[ ]) int f2(char *s)

{ int k=0; { char *ss;

while(s[k]!='\0') ;

k++; return k; ;

} return ;

}

(9) ss=s

(10) ‘\0’

(11) s-ss-1

4.When input is the names and scores of 30 students, print the name and score of the student who have the highest score.

#include <stdio.h>

struct student{

char name[10];

int score;

};

void main( )

{

int k;

struct student s[30], *ptr;

struct student *f(struct student *stud, int n);

for(k=0; k<30; k++)

《C Programming》TEST PAPER, June 20, 2003 8 /8

浙江大学c程2002B试卷E

scanf("%s%d", s[k].name, &s[k].score);

printf("%s %d\n", ptr->name, ptr->score); }

struct student *f(struct student *stud, int n) {

struct student * pmax, *p;

;

for(p=stud; p<stud+n; p++)

if(p->score > pmax->score) return }

(12) ptr=f(s,30)

(13) pmax=stud

(14) pmax=p

(15) pmax

C Programming》TEST PAPER, June 20, 2003 9 /8 《

…… 此处隐藏:34字,全部文档内容请下载后查看。喜欢就下载吧 ……
浙江大学c程2002B试卷E(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/38703.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)