浙大14年C语言专题试卷-英文(2)

2019-08-30 13:40

6. When input: 8 1 2 3 4 5 6 7 8, the following program will print out ____________.

#include #include

void F1(int *a, int n) {

int t, *b = a + n - 1;

while (a < b) { t = *a;

*a = *b; *b = t; a++;

b--; } }

void F2(int *a, int n) {

int i,t;

if (n <= 1) return;

for (i = 0; i < n/2; i++){ t = *(a + i);

*(a + i) = *(a + n - 1 - i); *(a + n - 1 - i) = t; } }

int main(void ) {

int i, n, *a;

scanf(\

if ((a = (int*)malloc(n*sizeof(int))) == NULL) return 2; for (i = 0; i

for (i = 0; i < n; i++) printf(\ return 0; }

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

1. There is an increasing ordered (升序) character list in a text file in.txt. The following

program read in this list, calculate the number of duplicates(重复) and write each character and its frequency of occurrence (>1) (大于1的出现次数) into the file out.txt. For example, if the in.txt contains “abbcdddddddddddde”, the list “ab2cd12e” will be written into out.txt.

“Fundamentals of Programming” Term Examination Paper, Jan 28, 2015 6 / 8

#include

main() {

FILE *fp1, *fp2; char last, c; int count=0;

fp1=fopen(\ fp2=fopen(\

if (_______(1)_______) return (0); last='\\0';

while (______(2)_____) { count++; if (c!=last) { if (count>1) _______(3)______; count=0; _______(4)______; last=___(5)____; } }

fclose(fp1); fclose(fp2); }

2. Function strncat(char *ret, char *s2, int n) copy at most n characters from s2 to ret.

The output of the following program is: WooMan

GoodWoMan

Please complete the program.

#include

char *strncat(char *ret, char *s2, int n) {

char *s1=ret;

if (n>0) {

while (_____(6)____); s1--;

while (*s1++=_____(7)____) { if (--n>0) continue;

*s1=_____(8)_____; break; }

return ret; } else {

return s1;

}

}

“Fundamentals of Programming” Term Examination Paper, Jan 28, 2015 7 / 8

main() {

char s[100]=”Good”;

char t1[100]=”Woo”; char t2[100]=”Manager”;

strncat(____(9)_____);

printf(“%s\\n”, t1);

strncat(____(10)_____); printf(“%s\\n”, s);

}

“Fundamentals of Programming” Term Examination Paper, Jan 28, 2015

8 / 8


浙大14年C语言专题试卷-英文(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:枯草芽孢杆菌感受态细胞的制备和转化

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: