C语言程序设计期末复习题(分析程序或程序段)新.doc
文本预览下载声明
第三部分 分析程序或程序段
分析程序或程序段,给出下列程序的运行结果:
1.#includestdio.h
main()
{
int i=16,j,x=6;
j=i++ +1;
x*=i=j;
printf(“%d,%d\n”,j,x);
}
运行结果是:
2.#includestdio.h
main()
{
int a,b,c,d;
a=c=0;
b=1;
d=20;
if(a) d=d-10;
else if(!b)
if(!c) d=25;
else d=15;
printf(“d=%d\n”,d);
}
运行结果:
main()
{
int i=10;
switch(i){
case 9: i+=1;
case 10: i+=1;
case 11: i+=1;
default : i+=1;
}
printf(“%d”,i);
}
运行结果:
4.#includestdio.h
main()
{
int a[]={1,2,3,4},i,j,s=0;
j=1;
for(i=3;i=0;i--)
{
s=s+a[i]*j;
j=j*10;
}
printf(s=%d\n,s);
}
运行结果:
5.func(int x)
{ x=20; }
main()
{
int x=10;
func(x);
printf(“%d”,x);
}
运行结果:10
6. #include stdio.h
main()
{
int x = 8 , y = 12;
printf(%d %d\n, x++, ++y);
printf(%d %d\n, x, y);
}
运行结果是:
7.
#include stdio.h
void Func(int b[])
{ int j;
for (j=0; j4; j++)
{ b[j] = j; }
}
main()
{ static int a[] = {5,6,7,8},i;
Func(a);
for (i=0; i4; i++)
{ printf(%d\n, a[i]); }
}
运行结果是:
8.
#include stdio.h
main()
{ int cube( int y );
int x;
for(x=1;x=5;x++)
printf(“%d ”, cube( x ) );
}
int cube( int y )
{ return 2*y; }
运行结果是:
9.
#include stdio.h
void Func(void);
main()
{ int i;
for (i = 0; i 2; i++)
{ Func(); }
}
void Func(void)
{ static int times = 1;
printf(Func() was called %d time(s).\n, times++);
}
运行结果是:
10.
#includestring.h
#includestdio.h
#define ARR_SIZE 80
void Inverse(char str[]);
main()
{ char a[ARR_SIZE];
printf(Please enter a string: );
gets(a);
Inverse(a);
printf(The inversed string is: );
puts(a);
}
void Inverse(char str[])
{ int len, i = 0, j;
char temp;
len=strlen(str);
for (j=len-1; ij; i++, j--)
{ temp = str[i];
str[j] = str[i];
str[j] = temp;
}
}
运行时键盘上输入ASDFG,结果是:
11. #include stdio.h
void Func(void);
main()
{ int i;
for (i=0; i5; i++)
{ Func(); }
}
void Func(void)
{ static int a = 1;
int b = 2, c;
c = a + b;
a++;
b++;
printf(%3d, c);
}
运行结果是:
12.
#include stdio.h
int
显示全部