barnabe0057

TP_Tableaux

Feb 20th, 2022
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MNS // Note: actual namespace depends on the project name.
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Afficher un mot dans un tableau de mots
  10.             string[] mots = { "ACAB", "Communisme", "Anarchisme", "Rouge", "Noir" };
  11.  
  12.             Console.WriteLine(mots[2]);
  13.  
  14.             int[] notes = { 17, 18, 15, 14, 10 };
  15.             Console.WriteLine(MoyenneTableau(notes));
  16.  
  17.             Console.WriteLine(NomMonstreAleatoire());
  18.         }
  19.  
  20.         public static int SommeTableau(int[] tableau)
  21.         {
  22.             int ARenvoyer = 0;
  23.  
  24.             for (int i = 0; i < tableau.Length; i++)
  25.             {
  26.                 ARenvoyer += tableau[i];
  27.             }
  28.  
  29.             return ARenvoyer;
  30.         }
  31.  
  32.         public static int MoyenneTableau(int[] tableau)
  33.         {
  34.             return SommeTableau(tableau) / tableau.Length;
  35.         }
  36.  
  37.         public static string NomMonstreAleatoire()
  38.         {
  39.             string ARenvoyer = "";
  40.  
  41.             string[] nomsMonstres = { "Gobelin", "Zombie", "Dragon", "Orc", "Troll", "Elfe noir",
  42.             "Chimère", "Banshee", "Harpie", "Gorgone", "Manticore", "Minotaure", "Satyre"};
  43.  
  44.             string[] adjectifsMonstres = { "enragé", "magique", "maléfique", "démoniaque", "brutal"
  45.             , "infect", "visqueux", "maudit", "putride", "ténébreux", "corrompu"};
  46.  
  47.             Random r = new Random();
  48.  
  49.             int nombreAleatoireNom = r.Next(0, nomsMonstres.Length);
  50.             Thread.Sleep(100);
  51.             int nombreAleatoireAdjectif = r.Next(0, adjectifsMonstres.Length);
  52.  
  53.             ARenvoyer = nomsMonstres[nombreAleatoireNom] + " " + adjectifsMonstres[nombreAleatoireAdjectif];
  54.  
  55.             return ARenvoyer;
  56.         }
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment