C#怎么比较三个数的大小并按从大到小的顺序输出?要用if语句。
8个回答
展开全部
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);
}
}
}
测试过了绝对能用!是控制台应用程序!写的有点复杂!也可以用冒泡排序什么的写。。希望对你有用!谢谢!
展开全部
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);
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用冒泡排序
int [] scores = new int [3];//定义数组
int i,j;
int temp;
console.writeline("输入三位数");
for(i=0;i<3;i++){
console.writeline("输入第{0}个数",i+1);
scores[i]=int.parse(console.readline());
}
for(i=0;i<scores.length-1;i++){
for(j=0;j<scores.length-1-i;j++){
if(scores[j]>scores[j+1]){
temp=scores[j];
scores[j]=scores[j+1];
scores[j+1]=temp;
}
}
}
console.writeline("排序后的数字为");
for(i=0;i<scores.length;i++){
console.write("{0}\t",scores[i]);
}
给我分吧,我是用手机写的这段程序,花了20分钟呢,可怜的我,
int [] scores = new int [3];//定义数组
int i,j;
int temp;
console.writeline("输入三位数");
for(i=0;i<3;i++){
console.writeline("输入第{0}个数",i+1);
scores[i]=int.parse(console.readline());
}
for(i=0;i<scores.length-1;i++){
for(j=0;j<scores.length-1-i;j++){
if(scores[j]>scores[j+1]){
temp=scores[j];
scores[j]=scores[j+1];
scores[j+1]=temp;
}
}
}
console.writeline("排序后的数字为");
for(i=0;i<scores.length;i++){
console.write("{0}\t",scores[i]);
}
给我分吧,我是用手机写的这段程序,花了20分钟呢,可怜的我,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else if(c>a && c>b) (为了你明白我写出来了,可以直接写个else)
max=c;
if(a<b && a<c)
min=a;
else if(b<a && b<c)
min=b;
else if(c<a && c<b)
min=c;
if(a>b && a<c)
mid=a;
else if(b>a && b<c)
mid=b;
else if(c>a && c<b)
mid=c;
最简音的写法为MAX=(a>b)?((a>c)?a:c):((b>c)?b:c)剩下的就充分发挥你的逻辑能力吧
max=a;
else if(b>a && b>c)
max=b;
else if(c>a && c>b) (为了你明白我写出来了,可以直接写个else)
max=c;
if(a<b && a<c)
min=a;
else if(b<a && b<c)
min=b;
else if(c<a && c<b)
min=c;
if(a>b && a<c)
mid=a;
else if(b>a && b<c)
mid=b;
else if(c>a && c<b)
mid=c;
最简音的写法为MAX=(a>b)?((a>c)?a:c):((b>c)?b:c)剩下的就充分发挥你的逻辑能力吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用控制台做的:
using System;
class compare
{
public static void Main()
{
//任意声明个数组,也可以很多元素,或者自己输入赋值给元素;
int[] myarray = { 3, 2, 9 };
//利用冒泡排序对数组进行排序,这个写代码对任何一维数组都可以排序;
for (int i = 0; i < myarray.Length - 1; i++)
{
for (int j = 0; j < myarray.Length - 1 - i; j++)
{
if (myarray[j] < myarray[j + 1])
{
int temp = myarray[j + 1];
myarray[j + 1] = myarray[j];
myarray[j] = temp;
}
}
}
//输出结果;
for(int i = 0; i < myarray.Length;i++)
Console.Write(myarray[i]+" ");
Console.ReadLine();
}
}
测试了,行得通,希望你能学到知识……
using System;
class compare
{
public static void Main()
{
//任意声明个数组,也可以很多元素,或者自己输入赋值给元素;
int[] myarray = { 3, 2, 9 };
//利用冒泡排序对数组进行排序,这个写代码对任何一维数组都可以排序;
for (int i = 0; i < myarray.Length - 1; i++)
{
for (int j = 0; j < myarray.Length - 1 - i; j++)
{
if (myarray[j] < myarray[j + 1])
{
int temp = myarray[j + 1];
myarray[j + 1] = myarray[j];
myarray[j] = temp;
}
}
}
//输出结果;
for(int i = 0; i < myarray.Length;i++)
Console.Write(myarray[i]+" ");
Console.ReadLine();
}
}
测试了,行得通,希望你能学到知识……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询