阅读程序写成果试题
第四章 选取构造 (共20道题)
1. (于蕾)
#include <>
void main( )
{
int x,y,t;
x=7;y=9;
if(x<y)
{ t=x;x=y;y=t;}
printf("%d,%d\n" ,x,y );
}
运营成果:
9,7
2. (于蕾)
#include <>
void main( )
{
int x=1,a=2,b=3;
switch(x)
{
case 1: a--;break;
case 2: b++;break;
case 3: a++;b++;
}
printf("\na=%d,b=%d\n",a,b);
}
运营成果:
a=1,b=3
3. (于蕾)
#include <>
void main( )
{
char ch1 = 'E';
if(ch1 >= 'A')
ch1++;
else
ch1+=32;
printf("ch1 = %c\n",ch1);
}
运营成果:
ch1= F
4. (于蕾)
#include <>
void main( )
{
int x,y,t;
x=5;y=3;
if(x>y)
{ t=x;x=y;y=t;}
printf("%d,%d\n" ,x,y );
}
运营成果:
3,5
5. (王伟)
#include <>
int main()
{
int a,b,c,m;
printf("Enter three integers:");
scanf("%d%d%d",&a,&b,&c);
if(a<=b)
m=a;
else
m=b;
if(c<m)
m=c;
printf("m=%d\n",m);
return 0;
}
输入:21 22 23<回车>
运营成果:
m=21
6. (王伟)
#include <>
int main()
{
char ch1='a',ch2='B',ch3='E';
if(ch1>ch2)
if(ch2>ch3)
ch3++;
else
--ch3;
printf("ch3=%c\n",ch3);
return 0;
}
运营成果:
ch3=D
7. (王伟)
#include <>
int main()
{
float x,y;
scanf("%f",&x);
switch((int)x/10)
{
case 0:y=;
printf("y=%f\n",y);break;
case 1:y=2*x+1;
printf("y=%f\n",y);break;
case 2:y=3*x*x+2;
printf("y=%f\n",y);break;
default:
printf("No definition.\n");
}
return 0;
}
输入:<回车>
运营成果:
y=
8. (王伟)
#include <>
int main()
{
char ch1='A',ch2='B';
switch(ch1)
{
case 'A':
switch(ch2)
{
case 'B':printf("Good!\n");break;
case 'A':printf("Better!\n");break;
}
case 'B':printf("Best!\n");break;
}
return 0;
}
运营成果:
Good!
Best!
9. (王锋)
#include <>
void main()
{
float score;
score = 100;
if (score<60) printf("E\n");
else
switch( ( int ) score / 10 )
{ case 10:
C语言程序设计阅读程序写结果试题汇总 来自淘豆网www.taodocs.com转载请标明出处.