static void Main(string[] args) { int a = 10; //数组长度 int b = 0; //小数位数 int min = 5; //最小数 int max = 20; //最大数 decimal[] arr = new decimal[a]; decimal sum = 150; decimal num = 0; Random random = new Random(); for (int i = 0; i < a; i++) { arr[i] = random.Next(min,max); num += arr[i]; //Console.WriteLine(arr[i]); //Console.WriteLine(Math.Round(arr[i],2)); } for (int i = 0; i < a; i++) { arr[i] = sum / num * arr[i]; Console.WriteLine(Math.Round(arr[i], b)); } //foreach (var item in arr) //{ //} Console.ReadKey(); }