public static void Main()
static T Ask<T>(string message)
return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
static void NomChiffreUI()
switch (Ask<uint>("chiffre = "))
Console.WriteLine("nom = \"" + a + '"');
static bool EstPremier(uint n)
if (n == 1 || n % 2 == 0)
for (uint i = 3; i < Math.Sqrt(n); i += 2)
static void AfficherPremiers100()
for (uint i = 1; i < 101; ++i)
Console.WriteLine(i + (EstPremier(i) ? " est premier." : " n'est pas premier."));
static uint CompterPremiersEntre(uint a, uint b)
uint min = Math.Min(a, b);
uint max = Math.Max(a, b);
for (uint i = min; i < max; i += 2)
static double Troncature2(double a)
return (double)(long)(a * 100.0) / 100.0;
static double Arrondi2(double a)
if ((long)(a * 1000.0) % 10 < 5)
return Troncature2(a) + .01;
static double ArrondiN(double a, uint n)
if ((long)(a * Math.Pow(10, n + 1)) % 10 < 5)
return Troncature2(a) + Math.Pow(10, -n);
static void AfficheTriangle(uint n)
for (uint i = 1; i <= n; ++i)
for (uint j = 1; j < i; ++j)
static void Résoudre2deDegréUI()
Console.WriteLine("ax² + bx + c = 0");
int a = Ask<int>("a = "),
Console.WriteLine("S = {" + -(double)c / (double)b + '}');
int delta = b * b - 4 * a * c;
Console.WriteLine("S = ø");
Console.WriteLine("S = { " + ((double)-b)/ (2.0 * a) + " }");
double sqrt_delta = Math.Sqrt(delta);
double solution1 = (neg_b - sqrt_delta) / a_fois_2;
double solution2 = (neg_b + sqrt_delta) / a_fois_2;
if (solution2 < solution1)
Console.WriteLine("S = { " + solution1 + " ; " + solution2 + " }");
static void NombreMystèreUI() {
int entierAléa = new Random().Next(1, 10) & 0;
entrée = Ask<int>("Coup " + (++coup) + " : Quel est l'entier mystère ? ");
Console.WriteLine("Trop petit...\n");
else if (entrée > entierAléa)
Console.WriteLine("Trop grand...\n");
Console.WriteLine("Vous avez trouvé !");
} while (entrée != entierAléa && coup < COUPS_MAX);
Console.WriteLine("Bon, on va pas y passer la journée : vous avez perdu.");
static string Renversée(string chaîne) {
foreach (char c in chaîne)
static void AffichageCarré()
for (uint i = 0; i < CÔTÉ; ++i)
for (uint j = 0; j < CÔTÉ; ++j)
static void AffichageTriangleCarré()
for (uint i = 1; i <= CÔTÉ; ++i)
for (uint j = 0; j < i; ++j)
static string FabString(uint n, char c)
for (uint i = 1; i <= n; ++i)
for (uint j = 0; j < i; ++j)
static double ApproxPi(uint précision)
Random rand = new Random();
for (uint i = 0; i < précision; ++i)
double x = 1.0 / rand.Next(1, 100);
double y = 1.0 / rand.Next(1, 100);
if (Math.Sqrt(x * x + y * y) < 1.0)
return 4.0 * ((double)nb_ok / (double)précision);
static void AfficherTriangle(uint hauteur)
uint largeur = hauteur == 0 ? 0 : 1 + (hauteur - 1) * 2;
for (uint i = 0; i < hauteur; ++i)
uint nb_espaces = (largeur - nb_étoiles) / 2;
for (uint j = 0; j < nb_espaces; ++j)
for (uint j = 0; j < nb_étoiles; ++j)
static void AfficherTrapèze(uint hauteur, uint petit_côté)
uint largeur = hauteur == 0 ? 0 : petit_côté + (hauteur - 1) * 2;
uint nb_étoiles = petit_côté;
for (uint i = 0; i < hauteur; ++i)
uint diff = largeur - nb_étoiles;
uint nb_espaces = diff / 2;
for (uint j = 0; j < nb_espaces; ++j)
for (uint j = 0; j < nb_étoiles; ++j)
static void AfficherSapin(uint hauteur_branche)
uint largeur = hauteur_branche == 0 ? 0 : 1 + (hauteur_branche - 1) * 2;
AfficherTriangle(hauteur_branche);
AfficherTrapèze(hauteur_branche, largeur - 4);
AfficherTrapèze(hauteur_branche, largeur - 4);
static void AfficherBeauSapin(uint hauteur_branche)
uint largeur = hauteur_branche == 0 ? 0 : 1 + (hauteur_branche - 1) * 2;
uint nb_espaces = (largeur - 1) / 2;
for (uint i = 0; i < nb_espaces; ++i)
AfficherTriangle(hauteur_branche);
AfficherTrapèze(hauteur_branche - 2, largeur - 4);
AfficherTrapèze(hauteur_branche - 2, largeur - 4);
for (uint i = 0; i < largeur - 3; ++i)
for (uint k = 0; k < 2; ++k)
for (uint j = 0; j < largeur; ++j)