可以参考下面的代码:
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
min=a;
else if(b
min=b;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3;
Console.WriteLine("请输入三个整数");
n1 = Convert.ToInt32(Console.ReadLine());
n2 = Convert.ToInt32(Console.ReadLine());
n3 = Convert.ToInt32(Console.ReadLine());
if (n1 >n2)
{
n1 ^= n2;
n2 ^= n1;
n1 ^= n2;
}
if (n2 >n3)
{
n2 ^= n3;
n3 ^= n2;
n2 ^= n3;
}
if (n1 >n3)
{
n1 ^= n3;
n3 ^= n1;
n1 ^= n3;
}
Console.WriteLine("排序后:" + n1 + ' ' + n2 + ' ' + n3);
}
}
}
两个单引号中间有一个空格,否则为空字符。
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3;
Console.WriteLine("请输入三个整数,以回车分隔:");
n1 = Convert.ToInt32(Console.ReadLine());
n2 = Convert.ToInt32(Console.ReadLine());
n3 = Convert.ToInt32(Console.ReadLine());
if (n1 < n2)
{
n1 ^= n2;
n2 ^= n1;
n1 ^= n2;
}
if (n2 < n3)
{
n2 ^= n3;
n3 ^= n2;
n2 ^= n3;
}
if (n1 < n2)
{
n1 ^= n2;
n2 ^= n1;
n1 ^= n2;
}
Console.WriteLine("排序后:" + n1 + ' ' + n2 + ' ' + n3);
}
}
}
#include
main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if((a>=b)&&(b>=c)){
printf("%d %d %d\n",a,b,c);
}else if((a>=c)&&(c>=b)){
printf("%d %d %d\n",a,c,b);
}else if((b>=a)&&(a>=c)){
printf("%d %d %d\n",b,a,c);
}else if((b>=c)&&(c>=a)){
printf("%d %d %d\n",b,c,a);
}else if((c>=a)&&(a>=b)){
printf("%d %d %d\n",c,a,b);
}else if((c>=b)&&(b>=a)){
printf("%d %d %d\n",c,b,a);
}else{
printf("Error\n");
}
}