Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple d’utilisation de tableau à deux dimensions

ArrayList, Array, HashTable, BitArray
{filelink=18429}

    using System;
 
    public class Exemple2Dimensions
    {
        static public void Main ()
        {
             DateTime now = DateTime.Now;
             Random rand = new Random ((int) now.Millisecond);
 
             int [,] Exemple2Dimensions = new int [5,10];
             for (int x = 0; x < Exemple2Dimensions.GetLength (0); ++x)
             {
                 for (int y = 0; y < Exemple2Dimensions.GetLength(1); ++y)
                 {
                     Exemple2Dimensions [x, y] = 70 + rand.Next () % 31;
                 }
             }
             int [] Average = new int [10];
             Console.WriteLine ("Le résumé des notes:");
             Console.WriteLine ("Etudiants   1     2     3     4     5     6     7     8     9    10");
             Console.WriteLine ("        ------------------------------------------------------------");
 
             for (int x = 0; x < Exemple2Dimensions.GetLength (0); ++x)
             {
                 Console.Write ("Mati " + (x + 1) + " ");
                 for (int y = 0; y < Exemple2Dimensions.GetLength(1); ++y)
                 {
                     Average[y] += Exemple2Dimensions[x,y];
                     Console.Write ("{0,6:D}", Exemple2Dimensions[x,y]);
                 }
                 Console.WriteLine ();
             }
             Console.Write ("Moyen. ");
             foreach (int Avg in Average)
             {
                 Console.Write ("{0,6:D}", Avg / Exemple2Dimensions.GetLength(0));
             }
             Console.WriteLine ();
        }
    }

No comments yet.

Leave a Comment