1.下面程序运行结果为( A)请解释原因。
void main (){
char c = 'a';
if('a' <c <='z'){
printf("LOW");
}
else{
printf("Up");
}
}
A.LOW
B.UP
C.LOWUP
D.程序语法错误
因为c被赋予'a'的值所以'a'==c,因此'a'<c为0,而后0<='z'成立为1,于是输出LOW
2.请阅读以下程序,(D)。请对选项进行解释。
void main( )
{
int a = 5, b = 0, c = 0;
if (a = b + c)
printf ("***\n");
else
printf ("$$$\n");
}
A. 有语法错不能通过编译
B. 可以通过编译但不能通过连接
C. 输出***
D. 输出$$$
由运算优先级,先算相加,b+c=0,将0的值赋给a,故0位false,输出D
3.填空:以下程序运行结果是_______6______,请解释。
void main( ) { int m = 5; if (m++ > 5) printf("%d\n", m); else printf("%d\n", m--); } |
m++值为6> 5条件成立输出6
4.已知 int x = 10, y = 20, z = 30; 以下语句执行后x =___20_____, y=__30____,z=__30_____。请解释。
if (x > y) z = x; x = y; y = z; |
x>y 不成立,因此执行下一项,将y值赋给x,因此x为10,而后将z值赋给y,y=30,z=30
5.下面的程序的功能是根据输入的百分制成绩score,转换成相应的五分制成绩grade并打印输出。转换的标准为:
当90≦score≦100时,grade为A;
当80≦score﹤90时,grade为B;
当70≦score﹤80时,grade为C;
当60≦score﹤70时,grade为D;
当score﹤60时,grade为E;
请填空:(1)____&score______(2)__score/10________(3)__break________
(4)____9______(5)___8_______(6)_____7_____ (7)___6_______
#include <stdio.h>
void main ( ) {
int score, mark;
scanf ("%d",____(1)______);
mark = _____(2)_____;
switch (mark)
{
default: printf ("%d--E", score); ______(3)____;
case 10:
case___(4)___: printf ("%d--A", score); break;
case___(5)___: printf ("%d--B", score); break;
case___(6)___: printf ("%d--C", score); break;
case___(7)___: printf ("%d--D", score); break;
}
}
6.输入一个年份year,判断是否是闰年
#include <stdio.h>
void main(){
int year;
scanf("%d",&year);
if((year % 4 && year % 100 != 0)|| (year%400==0) ){
printf("是闰年\n");
}else{
printf("不是闰年");
}
}
7.输入3个数,numA,numB,numC,计算这三个数的最大值和最小值
#include <stdio.h>
int main() {
int numA, numB, numC;
printf("请输入三个整数:");
scanf("%d %d %d", &numA, &numB, &numC);
int max = numA;
int min = numA;
if (numB > max)
{
max = numB;
}
if (numC > max)
{
max = numC;
}
if (numB < min)
{
min = numB;
}
if (numC < min)
{
min = numC;
}
printf("最大值为:%d", max);
printf("最小值为:%d", min);
return 0;
}
8.
#include<stdio.h>
int main(){
char operator;
double firstNumber,secondNumber;
printf("请输入操作符(+、-、*、/):");
scanf("%c",&operator);
printf("请输入两个数字:");
scanf("%lf %lf",&firstNumber,&secondNumber);
switch(operator){
case '+':
printf("%.1lf + %.lf= %.1lf",firstNumber,secondNumber,firstNumber+secondNumber);
break;
case '-':
printf("%.1lf - %.lf= %.1lf",firstNumber,secondNumber,firstNumber-secondNumber);
break;
case '*':
printf("%.1lf * %.lf= %.1lf",firstNumber,secondNumber,firstNumber*secondNumber);
break;
case '/':
printf("%.1lf / %.lf= %.6f",firstNumber,secondNumber,firstNumber/secondNumber);
break;
default :
printf("Error! operator is not correct");
}
return 0;
}