2006年广西区等级考试二级C真题

出处:ExamLink.com收集整理 作者:王志南 日期:2007年03月29日 10时14分

29、下面程序运行后,其输出是(   )
main()
{static char s[30]=”abcdefg”;
 static char t[]=”abcd”;
 int i,j;
 i=0;
 while(s[i]!=’\0’)
  i++;
 j=0;
while(t[j]!=’\0’)
 {s[i+j]=t[j];
   j++;}
s[i+j]=’\0’;
printf(“%s\n”,s);
}
A. abcdabcdefg           B. abcdefg           C. abcd          D. abcdefgabcd
 
30、下面程序运行后,其输出是(   )
main()
{ int a[4][4],i,j,k;
  for(i=0;i<4;i++)
for(j=0;j<4;j++)
  a[i][j]=i+j;
   for(i=1;i<4;i++)
     for(j=i+1;j<4;j++)
       { k=a[i][j];
         a[i][j]=a[j][i];
         a[j][i]=k;
        }
for(i=0;i<4;i++)
{printf(“\n”);
  for(j=0;j<4;j++)
   printf(“%4d”,a[i][j]);}
}
A、0  1  2  3       B、0  1  2   3      C、0  1   2   3     D、3  2  1  0 
   1   2  3  4          1  2  5   4         1  2   4   2         4  3  2  1
   2   3  4  5          2   3  4  5         2   3  5   3         5  4  3  2
   3   4  5  6          3   4  5  6         3   4  6   4         6  5  4  3
31、下面程序运行后,其输出是(   )
main()
{ void sub();
  char s[10]=”a program”;  int num=4;
  sub(s,0,num-1);   sub(s,num,6);   sub(s,0,6);
  printf(“%s\n”,s);
}
void  sub(char *s,int num1,int num2)
{ char t,*p;
  p=s+num2;s=s+num1;
  while(s<p)
   {t=*s;  *s=*p;  *p=t;   s++;  p--;}
}
A.program     B.gram pro     C.pro gram      D.ogra pram
32、运行下面程序,从键盘输入四个字符xyz#,其输出是(  )
#include "stdio.h"
main()
{ void  recursion();
  recursion();
}
 void  recursion()
{char c;
  c=getchar();
 putchar(c);
if(c!=’#’)
 recursion();
putchar(c);
}
A、xyz#         B、xyz#xyz#      C、xyz##zyx      D、xyzxyz

第二卷(共30分)
说明:程序填空题,在空栏处填入适当的字符、语句,以构成一个正确的C语言程序。每空栏3分,两大题共10个空栏,全对得30分。
试题一:
  下面的程序是将一个十六进制数字字符串转换成与它等价的十进制整数值并输出。十六进制数的字符是从0到9和a到f或A到F。主函数负责收集字符,并判别它们是否是十六进制字符,函数htoi负责转换工作。
#include <stdio.h>
#define maxline 100
#define  eof   -1
#define  yes    1
#define  no     0
int htoi();
main()
{ int c,i,isdigit;
  char t[maxline];
  i=0;
  isdigit=no;
  while((c=_______________)!=eof&&i<maxline-1)
   {  if(c>=’0’&&c<=’9’||c>=’a’&&c<=’f’|| c>=’A’&&c<=’F’)
      { isdigit=yes;
        t[i++]=___________;
       }
      else  if(isdigit==yes)
          { isdigit=no;
            t[i]=’\0’;
            printf(“%d”,______________);
            i=0;
           }
      }
}
int htoi(char *s)
{  int i,n;
   n=0;
  for(i=0;s[i]!=’\0’;i++)
{ if(s[i]>=’0’&&s[i]<=’9’)  n=n*16+s[i]-______________;
  if(s[i]>=’a’&&s[i]<=’f’)  n=n*16+s[i]-‘a’+10;
  if(s[i]>=’A’&&s[i]<=’F’)  n=n*16+s[i]-‘A’+10; 
 }
return___________;
}
试题二:
    以下程序的功能是应用近似公式计算  e
计算每项分母的值,共取nmax项之和作为e  的近似值。
近似公式:
e  =1+x+x /2!+ x /3!+……+ x     /(nmax-1)!
float f2(int n)
{ if(n==1)
  return 1;
  else return____________________;
}
float f1(float x,int n)
{ int i;float j=______________;
  for(i=1;___________;i++)
   j=j*x;
  return j;
}
#define nmax  20
main()
{ float x,exp=1.0;int n;
  printf(“input x value:”);
  scanf(“%f”,&x);
  printf(“%f\n”,x);
  for(n=1;n<nmax;n++)
exp=______________;
printf(“x=%f,exp(x)=%f\n”,x,_______________);
}

答案:
第一卷:
1~5   BCCAA    6~10  DADBB   11~15  ADBCA   16~20  ABBDD
21~25  CCABA    26~30  CBCDA   31~32  DC
第二卷:
试题一:
getchar()
c
htoi(t)
‘0’
n
试题二:
f2(n-1)*n
1
i<=n
exp+f1(x,n)/f2(n)
exp
转贴于

 

最后更新时间:2008-05-28 11:43:59
文章评论
共有 0 位网友发表了评论
用户名: 新注册) 密码: 匿名评论 [查看所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
您可以用以下几种方式找到此文章

考试全流程