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

时间:2011-12-25 00:17:03

微信搜索关注"91考试网"公众号,领30元,获取事业编教师公务员等考试资料40G

22套题

一、程序填空题

#include  <stdio.h>

int fun(int  x)

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

  n=0;

  t=100;

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

  while(t<=__1__){

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

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

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

    if(s1+s2+s3==__3__)

    {  printf("%d ",t);

       n++;

    }

    t++;

  }

  return  n;

}

main()

{ int x=-1;

  while(x<0)

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

  printf("nThe result is: %dn",fun(x));

}

 

 

二、程序改错题

#include <stdio.h>

 

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

void fun (long  s, long t)

{   long  sl=10;

    s /= 10;

    *t = s % 10;

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

    while ( s < 0)

    {  s = s/100;

       *t = s%10*sl + *t;

       sl = sl * 10;

    }

}

 

main()

{  long   s, t;

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

   fun(s, &t);

   printf("The result is: %ldn", t);

}

 

 

三、程序编写题

#include <stdio.h>

#define   N   16

typedef  struct

{  char  num[10];

   int   s;

} STREC;

void  fun( STREC  a[] )

{

 

 

}

 

main()

{  STREC  s[N]={{"GA005",85},{"GA003",76},{"GA002",69},{"GA004",85},

                  {"GA001",91},{"GA007",72},{"GA008",64},{"GA006",87},

                  {"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},

                  {"GA011",66},{"GA017",64},{"GA018",64},{"GA016",72}};

   int  i;FILE *out ;

   fun( s );

   printf("The data after sorted :n");

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

   {  if( (i)%4==0 )printf("n");

      printf("%s  %4d  ",s[i].num,s[i].s);

   }

   printf("n");

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

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

   {  if( (i)%4==0 && i) fprintf(out, "n");

      fprintf(out, "%4d  ",s[i].s);

   }

   fprintf(out,"n");

   fclose(out) ;

}

 


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

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