2012全国计算机二级C语言(C++)题库 第21套题

时间:2011-12-25 00:16:02

微信搜索关注"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: %dn",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] = '';

}

 

main()

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

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

   fun(s, t);

   printf("The result is: %sn", 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: %ldn", 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=%ldn", a, b, c) ;

  }

  fclose(rf) ;

  fclose(wf) ;

}

 

 


微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G
【省市县地区导航】【考试题库导航】

电脑版  |  手机版  |  返回顶部