using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ch5_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            const int num = 3; //number of term
            const int n1 = 3, n2 = 5, n3 = 4;
            int [][] grades = new int[num][];
            grades [0] = new int[n1] {15, 18,12};
            grades [1] = new int[n2] { 18, 14, 17, 19, 16 };
            grades [2] = new int[n3] { 16, 15, 10, 18 };
            label1.Text = "The contents of jagged array : \n";
            int sumGrade = 0;
            float ave;
            foreach (int[] array in grades)
            {
                foreach (int grade in array)
                {
                    label1.Text += grade.ToString() + "     ";
                    sumGrade += grade;
                }
                label1.Text += "\n";
            }
            sumGrade *= 3;
            ave = (float)sumGrade / ((n1 + n2 + n3) * 3);
            label1.Text += "average = " + ave.ToString();
        }
    }
}
