资源描述
. .
一、 单项选择题
1.〔 A 〕是构成C语言程序的根本单位。
A、函数 B、过程 C、子程序 D、子例程
2.C语言程序从C开场执行。
A) 程序中第一条可执行语句 B) 程序中第一个函数
C) 程序中的main函数 D) 包含文件中的第一个函数
3、以下说法中正确的选项是〔 C 〕。
A、C语言程序总是从第一个定义的函数开场执行
B、在C语言程序中,要调用的函数必须在main( )函数中定义
C、C语言程序总是从main( )函数开场执行
D、C语言程序中的main( )函数必须放在程序的开场局部
4.以下关于C语言的说法错误的选项是〔 B 〕 。
A) C程序的工作过程是编辑、编译、连接、运行
B) C语言不区分大小写。
C) C程序的三种根本构造是顺序、选择、循环
D) C程序从main函数开场执行
5.以下正确的标识符是〔C 〕。
A.-a1 B.a[i] C.a2_i D.int t
6.以下C语言用户标识符中合法的是〔 B 〕。
A)3ax B)x C)case D)-e2 E)union
7.以下四组选项中,正确的C语言标识符是〔 C 〕。
A〕 %xB〕 a+b C〕a123D〕123
8、以下四组字符串中都可以用作C语言程序中的标识符的是〔 A 〕。
A、print _3d db8 aBc B、I\am one_half start$it 3pai
C、str_1 Cpp pow while D、Pxq My->book line# His.age
9.C语言中的简单数据类型包括〔D 〕。
A、整型、实型、逻辑型 B、整型、实型、逻辑型、字符型
C、整型、字符型、逻辑型 D、整型、实型、字符型
10.在C语言程序中,表达式5%2的结果是C。
A)2.5 B)2 C)1 D)3
11.如果int a=3,b=4;那么条件表达式"a<b? a:b"的值是__A__。
A) 3B) 4 C) 0D) 1
12.假设int x=2,y=3,z=4 那么表达式x<z?y:z的结果是(B).
A)4 B)3 C)2 D)0 E)1
13.C语言中,关系表达式和逻辑表达式的值是〔 B 〕 。
A)0 B)0或1C) 1 D)‘T’或’F’
14. 下面( D )表达式的值为4.
A)11/3 B) 11.0/3
C) (float)11/3 D) (int)(11.0/3+0.5)
15.设整型变量 a=2,那么执行以下语句后,浮点型变量b的值不为0.5的是〔 B 〕
A.b=1.0/a B.b=(float)(1/a)
C.b=1/(float)a D.b=1/(a*1.0)
16. 假设“int n; float f=13.8;〞,那么执行“n=(int)f%3”后,n的值是〔A〕
A.1 B.4 C.4.333333 D.4.6
17. 以下对一维数组a的正确说明是:D
A) char a〔10〕; B) int a[];
C)int k=5,a[k]; D〕char a[3]={‘a’,’b’,’c’};
18.以下能对一维数组a进展初始化的语句是: ( C )
A. int a[5]=(0,1,2,3,4,) B. int a(5)={}
C. int a[3]={0,1,2} D. int a{5}={10*1}
19.在C语言中对一维整型数组的正确定义为 D。
A)int a(10); B)int n=10,a[n];
C)int n;a[n]; D)#define N 10
int a[N];
20、:int a[10]; 那么对a数组元素的正确引用是〔 D 〕。
A、a[10] B、a[3.5] C、a(5) D、a[0]
21.假设有以下数组说明,那么i=10;a[a[i]]元素数值是〔 B 〕。
int a[12]={1,4,7,10,2,5,8,11,3,6,9,12};
A.10 B.9 C.6 D.5
22.假设有说明:int a[][3]={{1,2,3},{4,5},{6,7}}; 那么数组a的第一维的大小为: ( B )
A. 2 B. 3 C. 4 D.无确定值
5 7 D) 3 6 9
23.对二维数组的正确定义是〔C 〕
A.int a[ ] [ ]={1,2,3,4,5,6}; B.int a[2] [ ]={1,2,3,4,5,6};
C.int a[ ] [3]={1,2,3,4,5,6}; D.int a[2,3]={1,2,3,4,5,6};
24.int a[3][4];那么对数组元素引用正确的选项是__C___
A)a[2][4] B)a[1,3] C)a[2][0] D)a(2)(1)
25.C语言中函数返回值的类型是由A 决定的.
A)函数定义时指定的类型 B) return语句中的表达式类型
C) 调用该函数时的实参的数据类型 D) 形参的数据类型
26. 在C语言中,函数的数据类型是指( A )
A 函数返回值的数据类型 B. 函数形参的数据类型
C 调用该函数时的实参的数据类型 D.任意指定的数据类型
27. 在函数调用时,以下说法正确的选项是〔B 〕
A.函数调用后必须带回返回值
B.实际参数和形式参数可以同名
C.函数间的数据传递不可以使用全局变量
D.主调函数和被调函数总是在同一个文件里
28.在C语言中,表示静态存储类别的关键字是: 〔 C〕
A) auto B) register C) static D) extern
29.未指定存储类别的变量,其隐含的存储类别为〔 A〕。
A)auto B)static C)extern D)register
30. 假设有以下说明语句:
struct student
{ int num;
char name[ ];
float score;
}stu;
那么下面的表达不正确的选项是: ( D )
A. struct是构造体类型的关键字
B. struct student 是用户定义的构造体类型
C. num, score都是构造体成员名
D. stu是用户定义的构造体类型名
31.假设有以下说明语句:
struct date
{ int year;
int month;
int day;
}brithday;
那么下面的表达不正确的选项是__C___.
A) struct是声明构造体类型时用的关键字
B) struct date 是用户定义的构造体类型名
C) brithday是用户定义的构造体类型名
D) year,day 都是构造体成员名
32. 以下对构造变量stul中成员age的非法引用是B
struct student
{ int age;
int num;
}stu1,*p;
p=&stu1;
A) stu1.age B) student.age C) p->age D) (*p).age
33.设有如下定义:
struck sk
{int a;
float b;
}data;
int*p;
假设要使P指向data中的a域,正确的赋值语句是C
A) p=&a; B) p=data.a; C) p=&data.a; D)*p=data.a;
34.设有以下说明语句:
typedef struct stu
{ int a;
float b;
} stutype;
那么下面表达中错误的选项是〔 D〕。
A、struct是构造类型的关键字
B、struct stu是用户定义的构造类型
C、a和b都是构造成员名
D、stutype是用户定义的构造体变量名
35. 语句int *p;说明了C。
A)p是指向一维数组的指针
B)p是指向函数的指针,该函数返回一int型数据
C)p是指向int型数据的指针
D)p是函数名,该函数返回一指向int型数据的指针
36.以下不正确的定义是〔 A 〕。
A. int *p=&i,i; B.int *p,i;
C.int i,*p=&i; D.int i,*p;
37. 假设有说明:int n=2,*p=&n,*q=p,那么以下非法的赋值语句是: 〔D 〕
A〕p=q B〕*p=*q C〕n=*q D〕p=n
38.有语句:int a[10],;那么B是对指针变量p的正确定义和初始化。
A)int p=*a; B)int *p=a; C)int p=&a; D)int *p=&a;
39.假设有说明语句“int a[5],*p=a;〞,那么对数组元素的正确引用是( C )。
A.a[p] B.p[a] C.*(p+2) D.p+2
40. 有如下程序
int a[10]={1,2,3,4,5,6,7,8,9,10},*P=a;
那么数值为9的表达式是B
A) *P+9 B) *(P+8) C) *P+=9 D) P+8
41. 在C语言中,以 D 作为字符串完毕标志
A)’\n’ B)’’C) ’0’ D)’\0’
42.以下数据中属于“字符串常量〞的是〔 A 〕。
A.“a〞 B.{ABC} C.‘abc\0’ D.‘a’
43.char x[]="hello", y[]={'h','e','a','b','e'};, 那么关于两个数组长度的正确描述是B .
A)一样 B)x大于y C)x小于y D)以上答案都不对
44. 下面各函数中能实现翻开文件功能的是A
A)fopen B) fgetcC) fputc D) fclose
45. 以下语句中,把变量fp说明为一个文件型指针的是( A ) 。
A) FILE *fp; B) FILE fp;
C) file *fp; D) file fp;
46.以读写方式翻开一个已有的文本文件file1,并且FILE *fp,下面fopen函数正确的调用方式是( B )。
A.fp=fopen(“file1”,“r〞)
B.fp=fopen(“file1”,“r+〞)
C.fp=fopen(“file1”,“rb〞)
D.fp=fopen(“file1”,“w〞)
二、 读程序
根本输入输出及流程控制
1.
#include <stdio.h>
main()
{ int a=1,b=3,c=5;
if (c==a+b)
printf("yes\n");
else
printf("no\n");
}
运行结果为:no
2.
#include <stdio.h>
main()
{ int a=12, b= -34, c=56, min=0;
min=a;
if(min>b)
min=b;
if(min>c)
min=c;
printf("min=%d", min);
}
运行结果为:min=-34
3.
#include <stdio.h>
main()
{ int x=2,y= -1,z=5;
if(x<y)
if(y<0)
z=0;
else
z=z+1;
printf(“%d\n〞,z);
}
运行结果为:5
4.
#include <stdio.h>
main()
{ float a,b,c,t;
a=3;
b=7;
c=1;
if(a>b)
{t=a;a=b;b=t;}
if(a>c)
{t=a;a=c;c=t;}
if(b>c)
{t=b;b=c;c=t;}
printf("%5.2f,%5.2f,%5.2f",a,b,c);
}
运行结果为:1.00, 2.00, 7.00
5.
#include < stdio .h >
main ( )
{ float c=3.0 , d=4.0;
if ( c>d ) c=5.0;
else
if ( c==d ) c=6.0;
else c=7.0;
printf ( “%.1f\n〞,c ) ;
}
运行结果为:7.0
6.
#include <stdio.h>
main()
{ int m;
scanf("%d", &m);
if (m >= 0)
{ if (m%2 == 0) printf("%d is a positive even\n", m);
else printf("%d is a positive odd\n", m); }
else
{ if (m % 2 == 0) printf("%d is a negative even\n", m);
else printf("%d is a negative odd\n", m); }
}
假设键入-9,那么运行结果为:-9 is a negative odd
7.
#include <stdio.h>
main()
{ int num=0;
while(num<=2){ num++;printf("%d\n",num);}
}
运行结果为:
1
2
3
8.
#include <stdio.h>
main( )
{ int sum=10,n=1;
while(n<3){sum=sum-n; n++;}
printf(“%d,%d〞,n,sum);
}
运行结果为:3,7
9.
#include <stdio.h>
main()
{ int num,c;
scanf("%d",&num);
do{c=num%10; printf("%d",c);}while((num/=10)>0);
printf("\n");
}
从键盘输入23,那么运行结果为:32
10
#include <stdio.h>
main()
{ int s=0,a=5,n;
scanf("%d",&n);
do{ s+=1; a=a-2; }while(a!=n);
printf("%d,%d\n",s,a);
}
假设输入的值1,运行结果为: 2,1
11.
#include "stdio.h"
main()
{char c;
c=getchar();
while(c!='?') {putchar(c); c=getchar();}
}
如果从键盘输入abcde?fgh〔回车〕
运行结果为:abcde
12.
#include <stdio.h>
main()
{ char c;
while((c=getchar())!=’$’)
{ if(‘A’<=c&&c<=‘Z’) putchar(c);
else if(‘a’<=c&&c<=‘z’) putchar(c-32); }
}
当输入为ab*AB%cd#CD$时,运行结果为:ABABCDCD
13.
#include <stdio.h>
main()
{ int x, y =0;
for(x=1;x<=10;x++)
{ if(y>=10)
break;
y=y+x;
}
printf(“%d %d〞,y,x);
}
运行结果为:10 5
14.
#include<stdio.h>
main( )
{ char ch;
ch=getchar( );
switch(ch)
{ case ‘A’ : printf(“%c〞,’A’);
case ‘B’ : printf(“%c〞,’B’); break;
default: printf(“%s\n〞,〞other〞);
} }
当从键盘输入字母A时,运行结果为:AB
15.
#include <stdio.h>
main( )
{ int a=1,b=0;
scanf(“%d〞,&a);
switch(a)
{ case 1: b=1;break;
case 2: b=2;break;
default : b=10;}
printf("%d ", b);
}
假设键盘输入5,运行结果为:10
16.
#include <stdio.h>
main()_
{ char grade=’C’;
switch(grade)
{ case ‘A’: printf(“90-100\n〞);
case ‘B’: printf(“80-90\n〞);
case ‘C’: printf(“70-80\n〞);
case ‘D’: printf(“60-70\n〞); break;
case ‘E’: printf(“<60\n〞);
default : printf(“error!\n〞);
}
}
运行结果为:
70-80
60-70
17.
#include <stdio.h>
main()
{ int y=9;
for(;y>0;y- -)
if(y%3==0)
{ printf(%d〞,- -y);
continue;
}
}
运行结果为:
852
18.
#include <stdio.h>
main()
{ int i,sum=0;i=1;
do{sum=sum+i;i++;}while(i<=10);
printf(“%d〞,sum);
}
运行结果为:55
19.
#include <stdio.h>
#define N 4
main()
{ int i;
int x1=1,x2=2;
printf("\n");
for(i=1;i<=N;i++)
{ printf("%4d%4d",x1,x2);
if(i%2==0)
printf("\n");
x1=x1+x2;
x2=x2+x1;
}
}
运行结果为:
1 2 3 5
8 13 21 34
20
#include <stdio.h>
main( )
{ int x, y;
for(x=30, y=0; x>=10, y<10; x--, y++)
x/=2, y+=2;
printf(“x=%d,y=%d\n〞,x,y);
}
运行结果为:
x=0,y=12
21.
#include <stdio.h>
#define N 4
main( )
{ int i,j;
for(i=1;i<=N;i++)
{ for(j=1;j<i;j++)
printf(" ");
printf("*");
printf("\n");
}}
运行结果为:
*
*
*
*
数组
1.
#include <stdio.h>
main()
{ int i,a[10];
for(i=9;i>=0;i--)
a[i]=10-i;
printf(“%d%d%d〞,a[2],a[5],a[8]);
}
运行结果为:
852
2.
#include <stdio.h>
main()
{int i,a[6];
for (i=0; i<6; i++)
a[i]=i;
for (i=5; i>=0 ; i--)
printf("%3d",a[i]);
}
运行结果为:
5 4 3 2 1 0
3.
#include <stdio.h>
main( )
{ int i,k,a[10],p[3];
k=5;
for(i=0;i<10;i++)
a[i]=i;
for(i=0;i<3;i++)
p[i]=a[i*(i+1)];
for(i=0;i<3;i++)
k+=p[i]*2;
printf("%d\n",k);
}
运行结果为:21
4.
#include <stdio.h>
int m[3][3]={{1},{2},{3}};
int n[3][3]={1,2 ,3};
main( )
{ printf(“%d,〞, m[1][0]+n[0][0]);
printf(“%d\n〞,m[0][1]+n[1][0]);
}
运行结果为:
3,0
5.
#include <stdio.h>
main()
{int i;
int x[3][3]={1,2,3,4,5,6,7,8,9};
for (i=1; i<3; i++)
printf("%d",x[i][3-i]);
}
运行结果为:
6 8
6.
#include <stdio.h>
main( )
{ int n[3][3], i, j;
for(i=0;i<3;i++ )
{for(j=0;j<3;j++ )
{n[i][j]=i+j;
printf(“%d 〞, n[i][j]);
}
printf(“\n〞);
}
}
运行结果为:
0 1 2
1 2 3
2 3 4
7.
#include <stdio.h>
main()
{
char diamond[][5]={{‘_’,’_’,’*’},{‘_‘,’*’,’_’,’*’},
{‘*’,’_’,’_‘,’_‘,’*’},{‘_’,’*’,’_’,’*’},{‘_’,’_’,’*’}};
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf(“%c〞,diamond[i][j]);
printf(“\n〞);
}
}注:“_〞代表一个空格。
运行结果为:
*
* *
* *
* *
*
8.
#include <stdio.h>
main( )
{ int i, f[10];
f[0]=f[1]=1;
for(i=2;i<10;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<10;i++)
{ if(i%4==0)
printf(“\n〞);
printf(“%d 〞,f[i]);
}
}
运行结果为:
1 1 2 3
5 8 13 21
34 55
9.
#include “stdio.h〞
func(int b[ ])
{ int j;
for(j=0;j<4;j++)
b[j]=j;
}
main( )
{ int a[4], i;
func(a);
for(i=0; i<4; i++)
printf(“%2d〞,a[i]);
}
运行结果为:
0 1 2 3
10.
#include <stdio.h>
main〔〕
{float fun(float x[]);
float ave,a[3]={4.5,2,4};
ave=fun〔a〕;
printf(“ave=%7.2f〞,ave);
}
float fun〔float x[]〕
{int j;
float aver=1;
for (j=0;j<3;j++)
aver=x[j]*aver;
return〔aver〕;
}
运行结果为:
ave= 36.00
11.
#include <stdio.h>
main()
{int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
for(i=0;i<=1;i++)
{for(j=0;j<=2;j++)
b[j][i]=a[i][j];
}
for(i=0;i<=2;i++)
{for(j=0;j<=1;j++)
printf("%5d",b[i][j]);
}
}
运行结果为:
1 4 2 5 3 6
12.
#include <stdio.h>
f(int b[],int n)
{int i,r;
r=1;
for (i=0;i<=n;i++)
r=r*b[i];
return (r);
}
main()
{int x,a[]={1,2,3,4,5,6,7,8,9};
x=f(a,3);
printf(“%d\n〞,x);
}
运行结果为:
24
13.
#include"stdio.h"
main()
{int j,k;
static int x[4][4],y[4][4];
for(j=0;j<4;j++)
for(k=j;k<4;k++)
x[j][k]=j+k;
for(j=0;j<4;j++)
for(k=j;k<4;k++)
y[k][j]=x[j][k];
for(j=0;j<4;j++)
for(k=0;k<4;k++)
printf("%d,",y[j][k]);
}
运行结果为:
0,0,0,0,1,2,0,0,2,3,4,0,3,4,5,6
函数
1.
#include <stdio.h>
int Sub(int a, int b)
{return (a- b);}
main()
{int x, y, result = 0;
scanf("%d,%d", &x,&y );
result = Sub(x,y ) ;
printf("result = %d\n",result);
}
当从键盘输入:6,3运行结果为:
result =3
2.
#include <stdio.h>
int min( int x, int y )
{ int m;
if ( x> y ) m = x;
else m = y;
return(m);
}
main() {
int a=3,b=5,abmin ;
abmin = min(a,b);
printf(“min is %d〞, abmin);
}
运行结果为:
min is 5
3.
#include<stdio.h>
func(int x) {
x=10;
printf(“%d, 〞,x);
}
main( )
{ int x=20;
func(x);
printf(“%d〞, x);
}
运行结果为:
10, 20
4.
#include <stdio.h>
int m=4;
int func(int x,int y)
{int m=1;
return(x*y-m);
}
main()
{int a=2,b=3;
printf("%d\n",m);
printf("%d\n",func(a,b)/m);
}
运行结果为:
4
1
5.
#include <stdio.h>
int fun(int a, int b)
{ if(a>b) return(a);
else return(b);
}
main()
{ int x=15, y=8, r;
r= fun(x,y);
printf("r=%d\n", r);
}
运行结果为:r=15
6.
#include <stdio.h>
int fac(int n)
{ int f=1,i;
for(i=1;i<=n;i++)
f=f * i;
return(f);
}
main()
{ int j,s;
scanf(“%d〞,&j);
s=fac(j);
printf("%d!=%d\n",j,s);
}
如果从键盘输入3,运行结果为:3!=6
7.
#include <stdio.h>
unsigned fun6(unsigned num)
{ unsigned k=1;
do
{ k*=num%10;
num/=10;
}while(num);
return k;
}
main()
{ unsigned n=26;
printf(“%d\n〞,fun6(n));
}
运行结果为:12
8.
#include <stdio.h>
int max(int x, int y);
main()
{int a,b,c
a=7;b=8;
c=max(a,b);
printf("Max is %d",c);
}
max(int x, int y)
{ int z;
z=x>y? x : y;
return(z) ;
}
运行结果为:
Max is 8
指针
1.
# include < stdio .h >
main ( )
{ int x[ ] = {10, 20, 30, 40, 50 };
int *p ;
p=x;
printf ( “%d〞, *(p+2 ) );
}
运行结果为:
30
2.
#include <stdio.h>
main( )
{ char s[]=〞abcdefg〞;
char *p;
p=s;
printf(“ch=%c\n〞,*(p+5));
}
运行结果为:
ch=f
3.
#include<stdio.h>
main ( )
{ int a[]={1, 2, 3, 4, 5} ;
int x, y, *p;
p=a;
x=*(p+2);
printf("%d:%d \n", *p, x);
}
运行结果为:
1:3
4.
#include<stdio.h>
main()
{ int arr[ ]={30,25,20,15,10,5}, *p=arr;
p++;
printf(“%d\n〞,*(p+3));
}
运行结果为:10
5.
#include <stdio.h>
main( )
{ int a[ ]={1, 2, 3, 4, 5, 6};
int x, y, *p;
p = &a[0];
x = *(p+2);
y = *(p+4);
printf(“*p=%d, x=%d, y=%d\n〞, *p, x, y);
}
运行结果为:
*p=1, x=3, y=5
6.
#include<stdio.h>
main( )
{ static char a[ ]=〞Program〞, *ptr;
for(ptr=a, ptr<a+7; ptr+=2)
putchar(*ptr);
}
运行结果为:
Prom
7.
#include <stdio.h>
char s[]=〞ABCD〞;
main()
{ char *p;
for(p=s;p<s+4;p++)
printf(“%c %s\n〞,*p,p);
}
运行结果为:
A ABCD
B BCD
C CD
D D
构造体
1.
#include<stdio.h>
struct st
{int x;
int y;
} a[2]={5, 7, 2, 9};
main()
{
printf("
展开阅读全文