✍编程题:
编写⼀个程序,对输⼊的4个整数,求出其中的最⼤值和最⼩值,并显⽰出来。
c# //a b c d
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
int d = Convert.ToInt32(Console.ReadLine());
int max = a, min = a;
if (max < b)
{
max = b;
}
if (max < c)
{
max = c;
}
if (max < d)
{
max = d;
}
if (min > b)
{
min = b;
}
if (min > c)
{
min = c;
}
if (min > d)
{
min = d;
}
Console.WriteLine("最大值是{0},最小值是{1}.", max, min);
✍编程题:
让⽤户输⼊两个整数,然后再输⼊0-3之间的⼀个数,0代表加法,1代表减法,2代表乘法,3代
表除法,计算这两个数字的结果
c# int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int op = Convert.ToInt32(Console.ReadLine());
int res = 0;
switch (op)
{
case 0:
res = a + b;
Console.WriteLine(res);
break;
case 1:
res = a - b;
Console.WriteLine(res);
break;
case 2:
res = a * b;
Console.WriteLine(res);
break;
case 3:
double res2 = a*1.0 / b;
Console.WriteLine(res2);
break;
}
✍编程题:
c#int x=1,a=0,b=0;
switch(x)
{
case 0:b++;break;
case 1:a++;break;
case 2:a++,b++;break;
}
Console.WriteLine("a="+a+" b="+b);
该程序的输出结果是( )
A、 a=2 b=1
B、 a=1 b=1
C、 a=1 b=0 ✔
D、 a=2 b=2
✍编程题:
以下关于switch和if语句说法正确的是:( )
A、switch可以判断变量在某个范围
B、switch可以同时对多个变量进⾏判断
C、能⽤if语句写的程序就能⽤switch语句写出
D、能⽤switch语句写的程序肯定能⽤if语句写出 ✔
✍编程题:
运⾏下⾯程序时,从键盘输⼊字⺟H,则输出结果时( )
c#char ch;
ch=Convert.ToChar(Console.ReadLine());
switch(ch)
{
case 'H':Console.WriteLine("Hello!");
case 'G':Console.WriteLine("Good Morning!!");
default:Console.WriteLine("Bye_Bye!");
}
A、 Hello! ✔
B、 Hello!
Good Morning!
C、 Hello!
Good Morning!
Bye_Bye!
D、 Hello!
Bye_Bye!