当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
  全国计算机等级四级机试试题及答案六
发布时间:2010/9/24 11:06:16 来源:www.xue.net 编辑:城市总裁吧

  16./* 请编写一个函数changestr(char *s),函数的功能是把s串中所有的字符前移一个位置,串中的第一个字符移到最后。

  例如:s串中原有的字符串为:Mn.123xyZ,则调用该函数后,s串中的内容为:n.123xyZM。函数ReadWrite()实现从文件in3.dat中读取两个字符串,并调用函数 changeStr(),最后把结果输出到文件out3.dat中。

  注意:部分源程序存放在文件PROG1.C中。

  请勿改动主函数main()和其它函数中的任何内容,仅在函数changeStr()的花括号中填入你编写的若干语句。*/

  #include

  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) ;

  }

  17./* 请编制函数CalValue(),其功能要求是:1.求出这个文件中共有多少个正整数totNum;2.求这些数中的十位数位置上的数字2、4和8的数的

  个数totCnt;以及不满足此条件的所有数的平均值totPjz,最后调用函数WriteDAT()把所求的结果输出到文件out7.DAT中。

  注意:部分源程序存放在PROG1.C中。

  请勿改动主函数main(),读数据函数ReadDAT()和输出数据函数

  WriteDAT()的内容。*/

  #include

  #include

  #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不能打开!\007\n") ;

  return ;

  }

  CalValue() ;

  printf("文件IN.DAT中共有正整数=%d个\n", totNum) ;

  printf("符合条件的正整数的个数=%d个\n", totCnt) ;

  printf("平均值=%.2lf\n", 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,", &xx[i++]) ;

  }

  fclose(fp) ;

  return 0 ;

  }

  void WriteDat(void)

  {

  FILE *fp ;

  fp = fopen("OUT7.DAT", "w") ;

  fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;

  fclose(fp) ;

  }

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved