输入三个数a b c 要求用C#按由小到大的顺序输出

输入三个数a b c 要求用C#按由小到大的顺序输出
2025-03-25 19:59:08
推荐回答(2个)
回答1:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 获取命令行参数
{
class Program
{
static void Main(string[] args)
{ int a,b,c,x;
int *pa,*pb,*pc;
pa=&a;//这里的指针前的星号去掉就行了
pb=&b;//
pc=&c;//三个都一样
printf("请输入3个整数\n");
scanf("%d%d%d",pa,pb,pc);
if(*pa>*pb)
{
x=*pa;
*pa=*pb;
*pb=x;
}
if(*pa>*pc)
{
x=*pa;
*pa=*pc;
*pc=x;
}
if(*pb>*pc)
{
x=*pb;
*pb=*pc;
*pc=x;
Console.WriteLine("这3个数由小到大的排列顺序为{0},{1},{2}",*pa,*pb,*pc);
}
}
}
望采纳 谢谢

回答2:

  • int[] nums = new int[] { 9, 6, 5};  

  • //从小到大排序  

  • Array.Sort(nums);  

  • foreach (var val in nums)  

  • {  

  • Console.Write(val + " ");  

  • }  

  • Console.WriteLine();