2000年9月机试试题 |
|
www.nanhushi.com 佚名 不详 |
2000年9月机试试题
1./* 程序prog1.c的功能是:选出100至1000之间所有个位数字与十位数字之和 被10除所得余数恰是百位数字的素数(如293)。计算并输出上述这些素数的个 数cnt以及这些素数值的和sum。 请考生编写函数countvalue( )实现程序的要求,最后调用函数writedat( )把 结果cnt和sum输出到文件out6.dat中。 注意:部分源程序存放在prog1.c中。 请勿改动主函数main( )和输出数据函数writedat( )的内容。 */ #include <stdio.h> int cnt, sum ;
void countvalue() {
}
void main() { cnt = sum = 0 ;
countvalue() ; printf("素数的个数=%d/n", cnt) ; printf("满足条件素数值的和=%d", sum) ; writedat() ; }
writedat() { file *fp ;
fp = fopen("out6.dat", "w") ; fprintf(fp, "%d/n%d/n", cnt, sum) ; fclose(fp) ; }
2. /* 编写函数sumvalue( ),它的功能是:计算正整数n的所有因子(1和n除外)之 和作为函数值返回。 例如:n=20时,函数值为21。 函数readwrite( )是实现从文件in9.dat中读取两个字符串,并调用函数 sumvalue(),最后把结果输出到文件out9.dat中。 注意:部分源程序存在文件prog1.c中,请勿改动主函数main()和其它函数 中的任何内容,仅在函数sumvalue()的花括号中填入你编写的若干语句。 */ #include <conio.h> #include <stdio.h> int sumvalue(int n) {
}
main() { clrscr() ; printf("%d/n", sumvalue(20)) ; readwrite() ; }
readwrite() { file *fp, *wf ; int i, n, s ;
fp = fopen("in9.dat","r") ; if(fp == null) { printf("数据文件in9.dat不存在!") ; return ; } wf = fopen("out9.dat","w") ; for(i = 0 ; i < 10 ; i++) { fscanf(fp, "%d", &n) ; s = sumvalue(n) ; fprintf(wf, "%d/n", s) ; } fclose(fp) ; fclose(wf) ; }
3./* 请编写一个函数changestr(char *s),函数的功能是把s串中所有的字 母改写成该字母的下一个字母,字母z改写成字母a。大写仍为大写字母, 小写字母仍为小写字母,其它的字符不变。 函数readwrite()实现从文件in2.dat中读取两个字符串,并调用函 数changestr(),最后把结果输出到文件out2.dat中。 注意:部分源程序存在文件prog1.c中。请勿改动主函数main()和其 它函数中的任何内容,仅在函数changestr()的花括号中填入你编写的若干语名。*/ #include <conio.h> #include <string.h> #include <stdio.h> #include <ctype.h> #define n 81 changestr ( char *s ) {
}
main( ) { char a[n] ; clrscr( ) ; printf ( "enter a string : " ) ; gets ( a ) ; printf ( "the original string is : " ) ; puts( a ) ;
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: 1999年9月机试试题及答案-已运行通过- 下一篇文章: 2001年9月机试试题 |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|