TOP

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

21套题

一、程序填空题

#include  <stdio.h>

int fun(int  x)

{ int  n, s1, s2, s3, t;

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

  n=__1__;

  t=100;

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

  while(t<=__2__)

  { s1=t%10;  s2=(t/10)%10;  s3=t/100;

    if(s1+s2+s3==15)

    {  printf("%d ",t);

       n++;

    }

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

    __3__;

  }

  return n;

}

main()

{ int  x=-1;

  while(x>999||x<0)

  {  printf("Please input(0<x<=999): ");  scanf("%d",&x);  }

  printf("\nThe result is: %d\n",fun(x));

}

 

 

二、程序改错题

#include <stdio.h>

#include <string.h>

 

void fun (char  *s, char  *t)

{

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

    int   i;

    sl = strlen(s);

    for (i=0; i<sl; i++)

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

       t[i] = s[sl-i];

    for (i=0; i<sl; i++)

          t[sl+i] = s[i];

    t[2*sl] = '\0';

}

 

main()

{  char s[100], t[100];

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

   fun(s, t);

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

}

 

 

三、程序编写题

#include <stdio.h>

void fun(int a, int b, long *c)

{

 

 

 

}

main()   /* 主函数 */

{  int a,b; long c;void NONO ();

   printf("Input a b:");

   scanf("%d%d", &a, &b);

   fun(a, b, &c);

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

   NONO();

}

void NONO ()

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

  FILE *rf, *wf ;

  int i, a,b ; long c ;

 

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

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

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

    fscanf(rf, "%d,%d", &a, &b) ;

    fun(a, b, &c) ;

    fprintf(wf, "a=%d,b=%d,c=%ld\n", a, b, c) ;

  }

  fclose(rf) ;

  fclose(wf) ;

}

 

 

Tags: 责任编辑:91kaoshiwang
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇2012全国计算机二级C语言(C++)题.. 下一篇2012全国计算机二级C语言(C++)题..

相关栏目

最新文章

推荐文章

网站客服QQ: 960335752 - 14613519 - 48225117