Professional Documents
Culture Documents
A题目
A题目
PAPER ( A )
Course Title: The C Programming Language
Year and Semester: 2016-2017 Spring
订
Scores
Teacher
Important note: your answers must be written on the answer sheet.
学号
Section 1: Fill in the blanks
(2 mark for each item, total 20 marks)
1.1 Variable names are made up of letters and digits; the first character must be
a ( letter ).
1.1 Variables and ( constants ) are the basic data objects manipulated in a
program.
班级
------------------------------------ 装
through the loop body; the body is always executed at least once.
1.3 The value of expression (int)9/2 is 4 .
1.4 The following code fragment will output 0.14; 000.618;3.14,0.618 .
#include<stdio.h>
main()
第 1 页,共 14 页
{float f=3.1415927; double d=0.6182345;
printf("%0.2f ,%3.3lf ",f,d);}
1.5 The statement for (i=1; i<=5; i++) printf(“%3d”,i*( i+1 ));
prints out the following numbers: 2 6 12 20 30 .
第 2 页,共 14 页
1.6 The output of the following statements is 7 .
main()
{ int n=8;
do
{ n--; printf("n=%d", n); }
while(n<4) ;}
1.7 The output of the following statements is m=10,n=25 .
int m, n;
for(m=0, n=0; m<10; m++)
{ if (m%2==0)
continue;
n += m; }
printf("m=%d,n=%d", m, n);
1.8 The output of the following statements is 6 .
#include <stdio.h>
#include <string.h>
main()
{ char bj[50]="What's\0your name!";
printf("%d\n",strlen(bj)); }\0 是结束符
1.9 The following program fragment prints out d=25 .
main()
{int a,b,c,d;
a=b=c=0; d=20;
if(a) d=d-10; b++;
if(b) d=20;
if(!c)d=25; else d=5;
printf("d=%d\n",d);}
第 3 页,共 14 页
1.10 The output of the following statements is 23489 .
#include<stdio.h>
#define N 5
main()
{int i,temp;
int a[N]={9,8,4,3,2};
for(i=0;i<N/2;i++)
{ temp=a[i];
a[i]=a[N-i-1];
a[N-i-1]=temp;}
for(i=0;i<N;i++) printf("%d",a[i]); }
Section 2: Single Choice(2 mark for each item, total 30 marks
)
2.1 Every C program consists of at least how many functions? A
A.1 B.2 C.3 D.4
2.2 Which of following is an legal user-define symbol? B
A.m.n B.MON_DAY C.6Set D.char
2.3 According to the declaration: int x=11; the value of expression (x++*1/3) is B .
A.3 B.4 C.0 D.3.667
第 4 页,共 14 页
2.4 According to the declaration: int (*p)[10], p is a(n) .
A.array B.pointer C.function D.element of array
2.5 The statement D is correct if a is an char variable and b is a double
precision float variable .
A.scanf(“%c,%f”, &a, &b) ; B.scanf(“a=%c b=%f”, &a, &b);
C.scanf(“%f%lf”, &a,&b) ; D.scanf(“%c%lf”, &a,&b );
第 5 页,共 14 页
2.6 After executing the following code fragment, the value of variable m is .
int m; for( m=0; m<9; m++ ) ; if(m<9) m++;
A.8 B.9 C.10 D.11
2.7 Which of the following statements is not an infinite loop(死循环)? .
A.for(k=10; ;k--)sum+=k;
B.while(1){x++};
C.for(;(c=getchar())!=’\n’;)printf(“%c”,c);
D.for(; ; x+=k);
2.8 Which of the following statements can determine whether the strings s1 and
s2 are equal? .
A.if(s1==s2) B.if(s1=s2) C.if(strcpy(s1,s2)) D.if (strcmp(s1,s2))
2.9 If strcat is used in the program, what kind of file shall be included? .
A.stdio.h B.string,h C.math.h D.stdlib.h exit
2.10 The following code fragment will output .
int a=1, s=0;
switch (a--) {
case 1: s+=10;
case 2: s+=10;
case 3: s+=10; break;
default: s+=3; }
printf("s=%d,a=%d",s,a);
A.s=10,a=0 B.s=30,a=0
C.s=30,a=1 D.s=3,a=1
第 6 页,共 14 页
2.11 The output of the following program is .
int s=0,a=10,n=2;
do { ++s; a=a-2; }while(a!=n);
printf("%d,%2d\n",s,a); }
A. 0,10 B.5,2 C.4, 4 D.4,2
2.12 is wrong.
A.char p; *p=“string”; B.int a,*p=&a;
C.while((*p2)!=‘\0’) D.int a[]={1,2,3,4} *p; p=a;
2.13 which of the follwing statement is correct ?
A.char 2a[5]={“GOOD”}; B.char a1[4]=“abcd”;
C.int a2[][3]={2,4,6,8,10} ; D.char s4[2][3]={“xyz”,“abc”};
2.14 The output of the following program is .
void change(char b[])
{ b[1]='B';}
main( )
{ char a[20]="Hello world! " ;
change(a); printf("%s\n",a);}
A.Hello world! B.H C.Bello world! D.HBllo world!
第 7 页,共 14 页
D.printf(" %d", sizeof(number.xiaoming));
Section 3: Read each of the following programs and answer ques
tions (4 marks for item, total marks: 12)
3.1 When input: What a wonderful day! <ENTER>, the output is Wht
wonderful dy! .
#include <stdio.h>
void delchar(char str[],char c)
{ int i,j;
for (i=0,j=0;str[i]!='\0';i++)
if (str[i]!=c)
str[j++]=str[i];
str[j]='\0';}
int main()
{ char str[80]; int i,j;
printf("please input the string:\n");
gets(str); delchar(str,'a');
puts(str); return 0;}
3.2 When input: 1 1 1 2 2 2 3 3 3<ENTER>,The following program will output
6 11 .
# include <stdio.h>
int f(int k )
{ return ++k; }
int main()
{ int a[3][3],sum=0;
int i,j;
printf("please enrer data:\n");
for(i=0;i<3;i++)
第 8 页,共 14 页
for(j=0;j<3;j++)
{scanf("%d",&a[i][j]);}
for(i=1;i<4;i++)
sum=sum+a[i][i-1];
printf("sum=%d\n",f(sum));
return 0; }
3.3 The following program will output a=1, b=4 .
#include<stdio.h>
main ()
void melon (int g, int * h);
{ int a = 1, b = 2;
melon ( a, &b );
printf ( "a = %d, b = %d", a, b ); }
void melon (int b, int * c)
{ b++;
*c = *c + b; }
第 9 页,共 14 页
t=a+
s=s+t;
a=a*10;
++count;
}
printf("s=%d\n",s);}
4.2 Bubble sorting(冒泡排序) is the most commonly used sorting method. It is a
sort of "exchange" thinking of the sort.The following program uses the bubbling
algorithm to sort. When input 9\n0\n-2\n25\n17,the following program will
output 25 17 9 0 -2 . Please fill the blanks.
#include <stdio.h>
#define N 5
main ( )
{ int i, j, t, a[N];
for(i=0; i<N; i++)
{ printf("enter No.%2d:", i+1);
scanf ("%d", &a[i]); }
for(i=0; ; i++)i<N-1
for (j=0; j<N-i-1; j++)/* compare two adjacent elements in the array */
if ( ) a[j]< a[j+1]
{ t=a[j]; a[j]=a[j+1]; a[j+1]=t; }
for(i=0; i<N; i++)
printf("%d ", a[i]); }
4.3 .There is an array s[3][4]. According to the following program ,please fill the
blanks.
第 10 页,共 14 页
#include <stdio.h> 9ffdd0 10 s[0][0]
#include <string.h> 9ffdd4 11 s[0][1]
main( ) 9ffdd8 12 s[0][2]
{ 9ffddc 13 s[0][3]
1. The s[0] and have the same address, but the meaning of the
representation is quite different.
2. If p=&s[1][1], *p= .
3. If p_4=&s[1], then the address of (p_4)is ,
4. The value of *(*(s+2)+1) is .
5. If p4[1]=*s+1,then the address of p4[1]= .
6. If p=&s[1][2], pp=&p, then **pp= .
第 11 页,共 14 页
Please write a program that can input x and output the value of y.
第 12 页,共 14 页
--------------------------------------
Scores
订
Teacher
-------------------------------------------------------------------
Answer
Answer
学号
Numbe
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10
r
Answer
Numbe
2.11 2.12 2.13 2.14 2.15
r
Answer
班级
------------------------------------ 装
Section 2 Single Choice(2 mark for each item, total 30 marks
)
Section 3
Read each of the following programs and answer questions
(4 marks for each item, total marks: 12)
线 -----------------
学生学院
3.1
3.2
3.3
BEIJING JIAOTONG UNIVERSITY
第 13 页,共 14 页
ANSWER SHEET ( A )
Section 4
According to the specification, complete each program
(2 mark for each blank, total: 20 marks)
Number 4.1 4.1 4.2 4.2 4.3
Answer
Section 5:Programming and drawing
(10 mark for item 5.2,8 mark for item 5.1, total: 18 marks)
第 14 页,共 14 页
BEIJING JIAOTONG UNIVERSITY
ANSWER SHEET ( A )
第 15 页,共 14 页
BEIJING JIAOTONG UNIVERSITY
ANSWER SHEET ( A )
第 16 页,共 14 页