Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Calculer la moyenne d’un tableau

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

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
 
  public static class Calcultableau
  {
 
    public static decimal moyenne(decimal[] valeurs)
    {
      if (valeurs == null || valeurs.Length == 0)
        throw new ArgumentNullException("valeurs");
 
      decimal acc = 0;
      for (int i = 0; i < valeurs.Length; i++)
      {
        acc += valeurs[i];
      }
 
      return acc / valeurs.Length;
    }
      public static void Main(string []arg)
      {
          Console.WriteLine("La moyenne du tableau new Decimal{12,16,14,18}: " +moyenne(new Decimal[] { 12, 16, 14, 18 }));
 
      }
  }

No comments yet.

Leave a Comment