TOP

2012全国计算机二级C语言(C++)题库 第4套题
2011-12-24 23:50:44 来源: 作者: 【 】 浏览:152次 评论:0
微信搜索关注"91考试网"公众号,领30元,获取公务员、事业编、教师等考试资料40G!

4套题

一、程序填空题

#include    <stdio.h>

#include    <stdlib.h>

int fun(char  *source, char  *target)

{  FILE  *fs,*ft;      char  ch;

/**********found**********/

   if((fs=fopen(source, ___1___))==NULL)

      return 0;

   if((ft=fopen(target, "w"))==NULL)

      return 0;

   printf("\nThe data in file :\n");

   ch=fgetc(fs);

/**********found**********/

   while(!feof(___2___))

   {  putchar( ch );

/**********found**********/

      fputc(ch,___3___);

      ch=fgetc(fs);

   }

   fclose(fs);  fclose(ft);

   printf("\n\n");

   return  1;

}

main()

{  char  sfname[20] ="myfile1",tfname[20]="myfile2";

   FILE  *myf;      int  i;      char  c;

   myf=fopen(sfname,"w");

   printf("\nThe original data :\n");

   for(i=1; i<30; i++){ c='A'+rand()%25;fprintf(myf,"%c",c); printf("%c",c); }

   fclose(myf);printf("\n\n");

   if (fun(sfname, tfname))  printf("Succeed!");

   else  printf("Fail!");

}

 

 

二、程序改错题

#include <stdio.h>

 

void fun (long  s, long *t)

{ int   d;

  long  sl=1;

    *t = 0;

    while ( s > 0)

    {  d = s%10;

/************found************/

       if (d%2=0)

       {  *t=d* sl+ *t;

          sl *= 10;

       }

/************found************/

       s \= 10;

    }

}

main()

{  long   s, t;

   printf("\nPlease enter s:"); scanf("%ld", &s);

   fun(s, &t);

   printf("The result is: %ld\n", t);

}

 

 

三、程序编写题

#include <stdio.h>

#include <string.h>

 

void fun(char *s, char t[])

{

 

 

 

}

 

main()

{

  char   s[100], t[100];

  void NONO (  );

  printf("\nPlease enter string S:"); scanf("%s", s);

  fun(s, t);

  printf("\nThe result is: %s\n", t);

  NONO();

}

 

void NONO ( )

{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */

  char s[100], t[100] ;

  FILE *rf, *wf ;

  int i ;

 

  rf = fopen("K:\\k01\\24010001\\in.dat","r") ;

  wf = fopen("K:\\k01\\24010001\\out.dat","w") ;

  for(i = 0 ; i < 10 ; i++) {

    fscanf(rf, "%s", s) ;

    fun(s, t) ;

    fprintf(wf, "%s\n", t) ;

  }

  fclose(rf) ;

  fclose(wf) ;

}

 

Tags: 责任编辑:91kaoshiwang
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇全国计算机二级-VF复习命令1 下一篇2012年计算机二级Access笔试数据..

相关栏目

最新文章

推荐文章

网站客服QQ: 960335752 - 14613519 - 48225117