题目
C#怎么比较三个数的大小并按从大到小的顺序输出?要用if语句.
提问时间:2021-01-19
答案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入三个数:");
double a = Convert.ToDouble (Console .ReadLine ());
double b = Convert.ToDouble(Console.ReadLine());
double c = Convert.ToDouble(Console.ReadLine());
double ? max=null ;
double ? middle =null ;
double ? min=null ;
if (a >= b && b >= c)
{
max = a;
middle = b;
min = c;
}
else
if(a>=c&&c>=b)
{
max = a;
middle = c;
min = b;
}
else
if (b >= a && a >= c)
{
max = b;
middle = a;
min = c;
}
else
if (b >= c && c >= a)
{
max = b;
middle = c;
min = a;
}
else
if (c>= a && a >= b)
{
max = c;
middle = a;
min = b;
}
else
if (c >= b && b >= a)
{
max = c;
middle = b;
min = a;
}
Console.WriteLine ("排序后的序列为(从大到小):{0}{1}{2}{3}{4}",max ,",",middle,"," ,min);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入三个数:");
double a = Convert.ToDouble (Console .ReadLine ());
double b = Convert.ToDouble(Console.ReadLine());
double c = Convert.ToDouble(Console.ReadLine());
double ? max=null ;
double ? middle =null ;
double ? min=null ;
if (a >= b && b >= c)
{
max = a;
middle = b;
min = c;
}
else
if(a>=c&&c>=b)
{
max = a;
middle = c;
min = b;
}
else
if (b >= a && a >= c)
{
max = b;
middle = a;
min = c;
}
else
if (b >= c && c >= a)
{
max = b;
middle = c;
min = a;
}
else
if (c>= a && a >= b)
{
max = c;
middle = a;
min = b;
}
else
if (c >= b && b >= a)
{
max = c;
middle = b;
min = a;
}
Console.WriteLine ("排序后的序列为(从大到小):{0}{1}{2}{3}{4}",max ,",",middle,"," ,min);
}
}
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1《中年闰土》中三个省略号省略了什么内容
- 2有没有生物,不能将无机碳转化为有机碳,但能将无机氮转化为有机氮?
- 3关于介词的英语题
- 4收拾房间4分,淘米3分,煮饭12分,炒菜7分,点火1分,美美用42分钟,妈妈说用21分.
- 5一个关于x的二次三项式,二次项的系数是1,一次项的系数和常数项的系数都是-1,这个多项数是()
- 6今年父亲的年龄段儿子的3倍,5年前,父亲的年龄是儿子的4倍,问父亲几岁?
- 7一道英语选择题(说明理由)谢谢!
- 8a family who quarrel among themselves WHO可以换成WHICH表一个整体吗
- 9白杨一文赞颂了什么?
- 10一种商品提价十分之一后,再降价十分之一后,现价比原价()a.贵了b.便宜了c.没变
热门考点