第三章-1(3-14作业)

  • 格式:doc
  • 大小:48.00 KB
  • 文档页数:4

一、选择题 (20分)
1.若x=0,y=3,z=3,以下表达式值为0的是
A. !x
B.x<y? 1:0
C. x%2&&y==z
D. y=x||z/3
2.以下运算符中优先级最低的运算符为 ,优先级最高的为。

A. &&
B. !
C. !=
D. ||
E. ?:
F. ==
3.若w=1,x=2,y=3,z=4,则条件表达式w<x?w:y<z?y:z的结果为。

A. 4
B. 3
C. 2
D. 1
4.若w,x,z均为int型变量,则执行以下语句后的输出为。

w=3;z=7;x=10;
printf("%d\n",x>10?x+100:x-10);
printf("%d\n",w++||z++);
printf("%d\n",!w>z);
printf("%d\n",w&&z);
A. 0
B. 1
C. 0
D. 0
1 1 1 1
1 1 0 0
1 1 1 0
二、读程序写结果(15分)
1. include <stdio.h>
main()
{ int a=-1,b=4,k;
k=(a++<=0)&&(!(b--<=0));
printf("%d,%d,%d\n",k,a,b);
}
2.
main()
{ int x=1,y=1,z=10;
if(z<0)
if(y>0) x=3;
else x=5;
printf("%d\t",x);
if(z=y<0) x=3;
else if(y==0) x=5;
else x=7;
printf("%d\t",x);
printf("%d\t",z);
}
3.
main()
{ char x=‘B’;
switch(x)
{ case ‘A’: printf(“It is A.”);
case ‘B’: printf(“It is B.”);
case ‘C’: printf(“It is C.”);
default: printf(“other.”);
}
}
二、填空题(每空2分,共40分)
1.若a=5,b=6,c=7,d=8,则表达式d=a/2&&b==c||!a的值为(1)
2.定义 int x=10,y,z;执行y=z=x;x=y==z后,变量x的值为(2)。

3.分段函数:输入x,计算y值,输出y,其中:
x<0 y=2x+3
x=0,y=0
x>0,y=(x+7)/3
#include <stdio.h>
main()
{
int x,y;
scanf("%d",&x);
if(x<0) (1) ;
(2) y=0;
(3) y=(x+7)/3;
printf(“%d”,y);
}
4.由键盘输入三个数,计算以这三个数为边长的三角形面积。

(1)
main()
{
(2) ;
printf("Please enter 3 reals:\n");
scanf("%f%f%f",&a,&b,&c);
if( (3) )
{ s=(a+b+c)*0.5;
s1=s*(s-a)*(s-b)*(s-c);
s= (4) ;
printf("\nArea of the triangle is %f\n",s);
}
(5)
printf("It is not triangle!\n");
}
5.有一方程a x2+bx+c=0,a,b,c的值由键盘输入,请编程序,打印出以下情况时方程的解。

(1) a=0,b≠0
(2) a=0,b=0,c=0
(3) a=0,b=0,c≠0
(4) a≠0,b2-4ac≥0
(5) a≠0,b2-4ac≤0
#include "math.h"
main()
{ float a,b,c,d,pr,pi,x1,x2;
scanf("%f%f%f",&a,&b,&c);
printf("a=%f,b=%f,c=%f\n",a,b,c);
if(a==0)
{ if( (1) )
printf("only one solution x=%f\n",-c/b);
else
if( (2) )printf("no solution\n");
else printf("x is any value\n");
}
else
{ d=b*b-4*a*c;
if( (3) )
{ x1=(-b+sqrt(d))/ (4) ;
x2=(-b-sqrt(d))/ (5) ;
printf("x1=%6.2f, x2=%6.2f\n",x1,x2);
}
else
{ pr=-b/(2*a); (6) ;
printf("x1=%6.2f +%6.2fi\n",pr,pi);
printf("x2=%6.2f -%6.2fi\n",pr,pi);
}
}
}
6.投票表决器:
–输入Y、y,打印agree
–输入N、n,打印disagree
–输入其他,打印lose
main()
{
char c;
scanf("%c",&c);
(1)
{
case ‘Y’:
case ‘y’: printf(“agree”); (2) ;
case ‘N’:
case ‘n’: printf(“disagree”); (3) ;
(4) :printf(“lose”);
}
三、编程题目:(25分,每题12.5分)
1.输入一个字符,判断它如果是小写字母输出其对应大写字母;如果是大写字母输出
其对应小写字母;如果是数字输出数字本身;如果是空格,输出“space”;如果不是上述情况,输出“other”。

2.读入1到7之间的某个数,输出表示一星期中相应的某一天的单词:Monday、
Tuesday等等,用switch语句做。