6. When input: 8 1 2 3 4 5 6 7 8, the following program will print out ____________.
#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