| 网站首页 | 考试学习 | 英语学习 | 求职 | 资源下载 | 出国留学 | 论文中心 | 箐箐校园 | 
资格类考试: 公务员考试 报关员考试 导游资格 注册会计 司法考试
外语类考试: 英语四六级 雅思 托福 GRE BEC PETS 职称英语
学历类考试: 高考 考研 自考 成考 专升本
计算机考试: 等级考试 水平考试 微软认证 思科认证 Linux认证
设为主页
联系站长
添加收藏夹
您现在的位置: 学子考试网 >> 考试学习 >> IT考试 >> 等级考试 >> 历年试题 >> 四级试题 >> 文章正文 用户登录 新用户注册
特 别 推 荐
· 报关员辅导
· 经济师辅导
· 会计职称辅导
· 注册会计师辅导
· 英语四级辅导
· 公共英语(PETS)辅导
· 商务英语(BEC)辅导
· 职称英语辅导
· 报检员辅导
· 造价工程师辅导
· 2006公务员网络辅导课程
· 查看更多...
最 新 热 门
最 新 推 荐
相 关 文 章
  • 英语六级考试一定要记住的

  • 2007年北京社招公务员考试

  • 四六级翻译范文(一)

  • 英语基础不好如何过四六级

  • 哈尔滨:四六级英语25日起报

  • 考生必看:全国英语等级考

  • 新东方名师支招:新四级通

  • 北京:非在校生四级成绩单

  • 四级425分成六级考试门槛 

  • 2001年9月全国计算机等级考

  • 1999年9月全国计算机等级考试四级机试试题及答案(已运行通过) 【字体:
    http://www.ks263.com 来源:本站原创 点击数: 更新:2005-1-20 【VIVI收藏
    1./*PROG1 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    各位数字之和是偶数的数的个数totCnt,以及满足此条件的这些数的算术平均
    值totpjZ,最后调用函数WriteDat()把所求的结果输出到文件OUT2.DAT中。
    注意:部分部分源程序存放在PROG1.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i;
    int a,b,c,d;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    {
    totNum++;
    a=xx[i]/1000;
    b=xx[i]/100-a*10;
    c=xx[i]/10-a*100-b*10;
    d=xx[i]%10;
    if((a+b+c+d)%2==0)
    {totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz=sum/totCnt;
    }


    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("OUT2.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    2./*PROG2 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数右移
    1位后,产生的新数是偶数的数的个数totCnt,以及满足此条件的这些数(右移
    前的值)的算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输出到
    文件OUT4.DAT中。
    注意:部分部分源程序存放在PROG2.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i,s;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    { totNum++;
    s=xx[i];
    s=s>>1;
    if ((s%2)==0)
    {
    totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz=sum/totCnt;
    }

    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("OUT4.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    3./*PROG3 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    个位数位置上的数字是3.6和9的数的数的个数totCnt,以及满足此条件的这些
    数的算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输出到文件
    OUT5.DAT中。
    注意:部分部分源程序存放在PROG3.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i,gw;
    double sum=0;
    for(i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    { totNum++;
    gw=xx[i]%10;
    if((gw==3)||(gw==6)||(gw==9))
    {
    totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz=sum/totCnt;
    }

    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("OUT5.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    4./*PROG4 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    千位数位置上的数字大于个位数位置上的数字的数的个数totCnt,以及满足此
    条件的这些数的算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输
    出到文件OUT8.DAT中。
    注意:部分部分源程序存放在PROG4.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i;
    int qw,gw;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    {
    totNum++;
    qw=xx[i]/1000;
    gw=xx[i]%10;
    if(qw>gw)
    {
    totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz=sum/totCnt;

    }

    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("OUT8.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    5./*PROG5 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    百位数位置上的数字是1、5和7的数的个数totCnt,以及满足此条件的这些数的
    算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输出到文件OUT7.DAT中。
    注意:部分部分源程序存放在PROG5.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i;
    int bw,qw;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if(xx[i]>0)
    {totNum++;
    qw=xx[i]/1000;
    bw=xx[i]/100-qw*10;
    if((bw==1)||(bw==5)||(bw==7))
    {totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz=sum/totCnt;
    }

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

    6./*PROG6 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数右移1
    位后,产生的新数是奇数的数的个数totCnt,以及满足此条件的这些数(右移前
    的值)的算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输出到文件
    OUT3.DAT中。
    注意:部分部分源程序存放在PROG6.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    {int i,s;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    {
    totNum++;
    s=xx[i];
    s=s>>1;
    if((s%2)==0)
    {
    totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz=sum/totCnt;

    }

    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("OUT3.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    7./*PROG7 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    百位数位置上的数字小于十位数位置上的数字的数的个数totCnt,以及满足此
    条件的这些数的算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输
    出到文件OUT9.DAT中。
    注意:部分部分源程序存放在PROG7.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    {int qw,bw,sw;
    int i;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    {
    totNum++;
    qw=xx[i]/1000;
    bw=xx[i]/100-qw*10;
    sw=xx[i]/10-qw*100-bw*10;
    if (bw<sw)
    {
    totCnt++;
    sum+=xx[i];
    }
    }
    totPjz=sum/totCnt;
    }

    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("OUT9.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    8./*PROG8 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    十位数位置上的数字是2、4和8的数的个数totCnt,以及满足此条件的这些数的
    算术平均值totpjZ,最后调用函数WriteDat()把所求的结果输出到文件OUT6.DAT中。
    注意:部分部分源程序存放在PROG8.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i,qw,bw,sw;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    {
    totNum++;
    qw=xx[i]/1000;
    bw=xx[i]/100-qw*10;
    sw=xx[i]/10-qw*100-bw*10;
    if ((sw==2)||(sw==4)||(sw==8))
    {
    totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz = sum / totCnt;
    }

    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("OUT6.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    9./*PROG9 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的
    千位数位置上的数字与十位数位置上的数字均为奇数的数的个数totCnt,以及
    满足此条件的这些数的算术平均值totpjZ,最后调用函数WriteDat()把所求的
    结果输出到文件OUT10.DAT中。
    注意:部分部分源程序存放在PROG9.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i,qw,bw,sw;
    double sum=0;
    for (i=0;i<MAXNUM;i++)
    if (xx[i]>0)
    {
    totNum++;
    qw=xx[i]/1000;
    bw=xx[i]/100-qw*10;
    sw=xx[i]/10-qw*100-bw*10;
    if (((qw%2)==0) && ((sw%2)==0))
    {
    totCnt++;
    sum=sum+xx[i];
    }
    }
    totPjz = sum / totCnt;
    }

    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("OUT10.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }

    10./*PROG10 已知在文件IN.DAT中存有若干个(个数<200)四位数字的正整数,
    函数ReadDat()是读取这若干个正整数并存入数组XX中。请编制函数CalValue(),
    其功能要求:1、求出这文件中共有多少个正整数totNum;2、求出这些数中的各
    位数字之和是奇数的数的个数totCnt,以及满足此条件的这些数的算术平均值
    totpjZ,最后调用函数WriteDat()把所求的结果输出到文件OUT1.DAT中。
    注意:部分部分源程序存放在PROG10.C中。
    请勿改动主函数main(),读数据函数ReacdDat()和输出数据函数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)
    { int i;
    int qw,bw,sw,gw;
    double sum=0;
    for ( i=0 ; i<MAXNUM; i++)
    if (xx[i] > 0)
    {
    totNum ++ ;
    qw = xx[i] / 1000;
    bw = xx[i] / 100 - qw * 10;
    sw = xx[i] / 10 - qw * 100- bw * 10;
    gw = xx[i] % 10;
    if ( ( (qw+bw+sw+gw) % 2)!=0)
    {
    totCnt ++ ;
    sum = sum + xx[i];
    }
    }
    totPjz = sum / totCnt;

    }

    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("OUT1.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", totNum, totCnt, totPjz) ;
    fclose(fp) ;
    }                      

              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 ) ;
    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\n", 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()的内容。 */
    #include <conio.h>
    #include <math.h>
    #include <stdio.h>
    float countValue()
    {

    }

    main()
    {
    clrscr();
    printf("实根=%f\n", countValue());
    printf(" %f\n",cos(countValue())-countValue());
    writeDAT();
    }

    writeDAT()
    {
    FILE *wf ;

    wf=fopen("out4.dat","w") ;
    fprintf(wf, "%f\n", 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不能打开!\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("OUT8.DAT", "w") ;
    fprintf(fp, "%d\n%d\n%.2lf\n", 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", n) ;
    ReadWrite() ;
    }

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

    rf = fopen("in1.dat", "r") ;
    wf = fopen("out1.dat", "w") ;
    while(i < 5) {
    fgets(str, 80, rf) ;
    fgets(substr, 10, rf) ;
    len = strlen(substr) - 1 ;
    ch = substr[len] ;
    if(ch == '\n' || ch == 0x1a) substr[len] = 0 ;
    n=findStr(str, substr);
    fprintf(wf, "%d\n", n) ;
    i++ ;
    }
    fclose(rf) ;
    fclose(wf) ;
    }

    7./* 请编写函数Void countValue(int *a,int *n),它的功能是:
    求出1到1000之内能被7或11整除但不能同时被7和11整除的所有整数,
    并放在数组a中,然后通过n返回这些数的个数。
    注意:部分源程序存入在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) ;
    }

    8./* 请编写一个函数changestr(char *s),函数的功能是把s串中所有的字
    符前移一个位置,串中的第一个字符移到最后。
    例如:s串中原有的字符串为:Mn.123xyZ,则调用该函数后,s串中的
    内容为:n.123xyZM。
    函数ReadWrite()实现从文件in3.dat中读取两个字符串,并调用函数
    changeStr(),最后把结果输出到文件out3.dat中。
    注意:部分源程序存放在文件PROG1.C中。
    请勿改动主函数main()和其它函数中的任何内容,仅在函数
    changeStr()的花括号中填入你编写的若干语句。*/
    #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) ;
    }


    9./* 请编制函数CalValue(),其功能要求是:1.求出这个文件中共有多
    少个正整数totNum;2.求这些数中的十位数位置上的数字2、4和8的数的
    个数totCnt;以及不满足此条件的所有数的平均值totPjz,最后调用函
    数WriteDAT()把所求的结果输出到文件out7.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不能打开!\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) ;
    }

    10./* 已知在文件IN.BAT中存有N个实数(N<200),函数ReadDAT()读取
    这N个实数并存入数组XX中。
    请编制函数CalValue(),其功能要求是:1.求出这N个实数的平
    均值aver;2.分别求出这N个实数的整数部分值的平均值averint以
    及其小数部分值的平均值averdel,最后调用函数WriteDAT()把所求
    的结果输出到文件out10.DAT中。
    注意:部分源程序存放在文件PROG1.C中。
    请勿改动主函数main(),读数据函数ReadDAT()和输出数据函数
    WreitDAT的内容。*/
    #include <stdio.h>
    #include <conio.h>
    #define MAXNUM 200

    float xx[MAXNUM] ;
    int N = 0 ; /* 文件IN.DAT中共有多少个实数 */
    double aver = 0.0 ; /* 平均值 */
    double averint = 0.0 ; /* 整数部分值的平均值 */
    double averdec = 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", N) ;
    printf("平均值=%.2lf\n", aver) ;
    printf("整数部分值的平均值=%.2lf\n", averint) ;
    printf("小数部分值的平均值=%.2lf\n", averdec) ;
    WriteDat() ;
    }

    int ReadDat(void)
    {
    FILE *fp ;
    int j ;

    if((fp = fopen("in.dat", "r")) == NULL) return 1 ;
    while(!feof(fp)) {
    fscanf(fp, "%f,", &xx[N]) ;
    if(xx[N] > 0.001) N++ ;
    }
    fclose(fp) ;
    return 0 ;
    }

    void WriteDat(void)
    {
    FILE *fp ;

    fp = fopen("OUT10.DAT", "w") ;
    fprintf(fp, "%d\n%.2lf\n%.2lf\n%.2lf\n", N, aver, averint, averdec) ;
    fclose(fp) ;
    }    

    文章录入:ks263.com    责任编辑:ks263.com 
  • 上一篇文章:

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