| 网站首页 | 自考 | 中考 | 高考 | MBA | 考研 | 成人高考 | 报关员 | 导游 | 司法 | 计算机 | 会计 | 英语 | 医学 | 小学 | 初中 | 高中 | 法律硕士 | 建筑工程 | 留言 | 
最新公告:     本站一直领先的专注于考试的网络媒体与服务平台,请大家互相支持!  [admin  2006年9月7日]        
 
您现在的位置: 试卷下载网 >> 计算机 >> 计算机等级考试 >> 文章正文
 
 
 
最新推荐 更多内容
 
 
相关文章
2006年全国计算机等级考…
2005年笔试题二级java及…
思科认证考试(CCNA…
微软MCSE2003认证新增实…
2001年度网络设计师级上…
2001年度网络程序员级下…
2001年度初级程序员…
2003年度系统设计师(高…
2002年程序员上午试题及…
2001年度系统设计师(高程…
更多内容
2000年9月机试试题(1)           
2000年9月机试试题(1)
作者:佚名 文章来源:不详更新时间:2006-5-30 8:22:44
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 ", cnt) ; 
printf("满足条件素数值的和=%d", sum) ; 
writeDAT() ; 


writeDAT() 

FILE *fp ; 

fp = fopen("OUT6.DAT", "w") ; 
fprintf(fp, "%d %d ", 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 ", 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 ", s) ; 
  共3页: 1 [2] [3] 下一页   

r>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 ) ; 
changeStr ( a ) ; 
printf ( "The string after modified : ") ; 
puts ( a ) ; 
ReadWrite( ) ; 


ReadWrite( ) 

int i ; 
char a[N] ; 
FILE *rf, *wf ; 

rf = fopen("in2.dat", "r") ; 
wf = fopen("out2.dat", "w") ; 
for(i = 0 ; i < 10 ; i++) { 
fscanf(rf, "%s", a) ; 
changeStr(a) ; 
fprintf(wf, "%s ", a) ; 

fclose(rf) ; 
fclose(wf) ; 


4./* 程序PROG1.C的功能是:利用以下所示的简单迭代方法求方程: 
cos(x)-x=0的一个实根。 
Xn+1=cos(Xn) 
迭代步骤如下: 
(1) 取x1初步值为0.0; 
(2) x0=x1,把x1,把x1的值赋给x0; 
(3) x1=cos(x0),求出一个新的x1; 
(4) 若x0-x1的绝对值小于0.000001,执行步骤(5),否则执行步骤(2); 
(5) 所求x1就是方程cos(x)-x=0的一个实根,作为函数值返回。 
请编写函数countValue()实现程序的要求,最后调用函数writeDAT()把 
结果输出到文件out4.dat中。 
注意:部分源程序存在文件PROG1.C中,请勿改动主函数main()和输出数 
据函数WriteDAT()的内容。 */&
  共3页: 上一页 [1] 2 [3] 下一页   

nbsp;
#include <conio.h> 
#include <math.h> 
#include <stdio.h> 
float countValue() 





main() 

clrscr(); 
printf("实根=%f ", countValue()); 
printf(" %f ",cos(countValue())-countValue()); 
writeDAT(); 


writeDAT() 

FILE *wf ; 

wf=fopen("out4.dat","w") ; 
fprintf(wf, "%f ", countValue()) ; 
fclose(wf) ; 


5./* 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数, 
函数ReadDAT()读取这些正整数并存入数组xx中。 
请编制函数CalValue()其功能要求是:1.求出这个文件中共有多 
少个正整数totNum;2.求出这些数中的各位数字之和是奇数的数的个 
数totCnt,以及不满足此条件的所有数的算术平均值totPjz,最后调 
用函数WriteDAT()把所求的结果输出到文件OUT8.DAT中。 
注意:部分源程序存放在PROG1.C中。 
请勿改动主函数main(),读数据函数ReadDAT()和输出数据函数 
WriteDAT()的内容。 */ 
#include <stdio.h> 
#include <conio.h> 
#define MAXNUM 200 

int xx[MAXNUM] ; 
int totNum = 0 ; /* 文件IN.DAT中共有多少个正整数 */ 
int totCnt = 0 ; /* 符合条件的正整数的个数 */ 
double totPjz = 0.0 ; /* 平均值 */ 

int ReadDat(void) ; 
void WriteDat(void) ; 

void CalValue(void) 





void main() 

clrscr() ; 
if(ReadDat()) { 
printf("数据文件IN.DAT不能打开!07 ") ; 
return ; 

CalValue() ; 
printf("文件IN.DAT中共有正整数=%d个 ", totNum) ; 
printf("符合条件的正整数的个数=%d个 ", totCnt) ; 
printf("平均值=%.2lf ", totPjz) ; 
WriteDat() ; 


int ReadDat(void) 

FILE *fp ; 
int i = 0 ; 

if((fp = fopen("in.dat", "r")) == NULL) return 1 ; 
while(!feof(fp)) { 
fscanf(fp, "%d,&qu#p#ot;, &xx[i++]) ; 

fclose(fp) ; 
return 0 ; 


void WriteDat(void) 

FILE *fp ; 

fp = fopen("OUT8.DAT", "w") ; 
fprintf(fp, "%d %d %.2lf ", totNum, totCnt, totPjz) ; 
fclose(fp) ; 


6./* 编写一个函数findstr(),该函数统计一个长度为2的子字符串在另一个 
字符串中出现的次数。例如,假定输入的字符串为“asd asasdfg asd as  
zx67 asd mklo”,子字符串为“as”,则输出6。 
函数ReadWrite()实现从文件in1.dat中读取两个字符串,并调用函数 
findStr(),最后把结果输出到文件out1.dat中。 
注意:部分源程序存在文件PROG1.C中。请勿改动主函数main()和其它 
函数中的任何内容,仅在函数findStr()的花括号中填入你编写的若干语句。*/ 
#include <stdio.h> 
#include <string.h> 
#include <conio.h> 

int findStr(char *str,char *substr) 





main() 

char str[81], substr[3] ; 
int n ; 

clrscr() ; 
gets(str) ; 
gets(substr) ; 
puts(str) ; 
puts(substr) ; 
n=findStr(str, substr) ; 
printf("n=%d ", n) ; 
ReadWrite() ; 


ReadWrite() 

char str[81], substr[3], ch; 
int n, len, i = 0; 
FILE *rf, *wf ; 

rf = fopen("in1.dat", "r") ; 
wf = fop

[1] [2] 下一页

文章录入:admin    责任编辑:admin 
 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口

     
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |