using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace shuzujichu
{
class Program
{
static void Main(string[] args)
{
//在數組中產生一批隨機數,記錄其中最大數,以及最大數的位置
const int N = 10;
int[] a = new int[N];
int max, max_i;
Random random = new Random();
for (int i = 0; i < N; i++)
{
a[i] = random.Next(10, 99);
}
max = a[0];
max_i = 0;
for (int i = 0; i < N; i++)
{
if (max < a[i])
{
max = a[i];
max_i = i;
}
}
for (int i = 0;i < N;i++)
{
Console.Write("{0} ",a[i]);
}
Console.WriteLine();
Console.Write("max:{0},location:{1}",max,max_i);
Console.ReadKey();
}
}
}
效果如圖: