Pouknouki

Dices Probability C# Script

Apr 10th, 2013
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             System.Random aleatoire = new System.Random();
  13.             int lancers = int.Parse(Console.ReadLine());
  14.             int[] nombreCotes = new int[12];
  15.             for (int i = 0; i <= lancers; i++)
  16.             {
  17.                 int t =System.Convert.ToInt32(aleatoire.NextDouble() * 6);
  18.                 int u = System.Convert.ToInt32(aleatoire.NextDouble() * 6);
  19.                 switch (t+u)
  20.                 {
  21.                     case 1:
  22.                         nombreCotes[0] = nombreCotes[0] + 1;
  23.                         break;
  24.                     case 2:
  25.                         nombreCotes[1] = nombreCotes[1] + 1;
  26.                         break;
  27.                     case 3:
  28.                         nombreCotes[2] = nombreCotes[2] + 1;
  29.                         break;
  30.                     case 4:
  31.                         nombreCotes[3] = nombreCotes[3] + 1;
  32.                         break;
  33.                     case 5:
  34.                         nombreCotes[4] = nombreCotes[4] + 1;
  35.                         break;
  36.                     case 6:
  37.                         nombreCotes[5] = nombreCotes[5] + 1;
  38.                         break;
  39.                     case 7:
  40.                         nombreCotes[6] = nombreCotes[6] + 1;
  41.                         break;
  42.                     case 8:
  43.                         nombreCotes[7] = nombreCotes[7] + 1;
  44.                         break;
  45.                     case 9:
  46.                         nombreCotes[8] = nombreCotes[8] + 1;
  47.                         break;
  48.                     case 10:
  49.                         nombreCotes[9] = nombreCotes[9] + 1;
  50.                         break;
  51.                     case 11:
  52.                         nombreCotes[10] = nombreCotes[10] + 1;
  53.                         break;
  54.                     case 12:
  55.                         nombreCotes[11] = nombreCotes[11] + 1;
  56.                         break;
  57.                 }
  58.             }
  59.             double total = 0;
  60.             for (int i = 1; i <= 12; i++)
  61.             {
  62.                 double frequence = System.Convert.ToDouble(nombreCotes[i - 1]) / System.Convert.ToDouble(lancers);
  63.                 Console.WriteLine("Pour " + i + ", l'effectif est de : " + nombreCotes[i-1] + ", la fréquence est de " + frequence);
  64.                 total = total + frequence;
  65.  
  66.             }
  67.             Console.WriteLine(total);
  68.             Console.ReadKey();
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment