- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace staggerArray
- {
- class Program
- {
- static void Main(string[] args)
- {
- int [][] a=new int[5][];
- Random ran = new Random();
- int[] sum = new int[a.Length];
- double num = 0;
- int i , temp=0;
- for ( i = 0; i < a.Length;i++ )
- {
- a[i] = new int[ran.Next(5)+1];
- if(temp < a[i].Length){
- temp = a[i].Length;
- }
- }
- for (i = 0; i < a.Length; i++)
- {
- Console.Write("第{0}行:", i + 1);
- for(int j = 0;j < a[i].Length;j++){
- a[i][j] = ran.Next(100)+1;
- Console.Write(a[i][j]);
- Console.Write("\\t");
- sum[i] += a[i][j];
- }
- for (int n = 1; n <= temp - a[i].Length; n ++ )
- {
- Console.Write("\\t");
- }
- num = (double)sum[i] / a[i].Length;
- Console.Write("平均值:{0:f2}",num);
- Console.WriteLine();
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0609201615047.html
来源: http://www.codesnippet.cn/detail/0609201615047.html