C# 代码:
static void Main(string[] args)
{
int n = 0, max = 0, min = 0, s = 0;
Console.Write("输入数字个数:");
n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n];
Console.WriteLine("输入数字:");
for (int i = 0; i < n; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
if (i == 0)
{
max = min = a[i];
}
if (max < a[i])
{
max = a[i];
}
if (min > a[i])
{
min = a[i];
}
}
s = max - min;
Console.WriteLine("最大值和最小值的差是:" + s);
Console.ReadLine();
}