Skip to content

Solutions possibles aux exercices de la semaine 4

static void ex1()
{
    for (int i = 0; i < 15; i++)
    { 
        Console.WriteLine("ATTENTION!");
    }
}
static void ex2()
{
    for (int i = 1; i < 11; i++)
    {
        Console.WriteLine("Nombre : " + i + " Carré : " + i * i + " Cube : " + i * i * i);
    }
}
static void ex3()
{
    double celsius = 0.0;

    for (int farenheit = -40; farenheit <= 40; farenheit = farenheit + 5)
    {
        celsius = 5.0 / 9.0 * (farenheit - 32.0);
        Console.WriteLine(celsius);
    }
}
static void ex4()
{
    double montant = 5.0;
    for (int i = 1; i <= 20; i++)
    {
        Console.WriteLine("Montant : " + montant * i + " Taxe : " + montant * i * 0.15);
    }
}
static void ex5()
{
    double total = 0.01;

    for (int i = 0; i < 30; i++)
    {
        total *= 2;
    }

    Console.WriteLine(total + "$ est mieux que 1M$");
}
static void ex6()
{
    for (int i = 1; i < 50; i += 2)
    {
        Console.WriteLine(i);
    }
}
static void ex7()
{
    int nbParLigne = 0;
    for (int i = 1; i < 50; i += 2)
    {
        Console.Write(i);
        nbParLigne++;
        if (nbParLigne == 5)
        {
            Console.WriteLine();
            nbParLigne = 0;
        }
    }
}
static void ex8a()
{
    // option 1
    string affichage = "";
    for (int i = 0; i < 4; i++)
    {
        affichage += "#";
        Console.WriteLine(affichage);
    }
    // option 2
    for (int i = 1; i <= 4; i++)
    {
        for (int j = 0; j < i; j++)
        {
            Console.Write("#");
        }
        Console.WriteLine();
    }
}
static void ex8b()
{
    // option 1
    string affichage = "";
    for (int i = 1; i <= 4; i++)
    {
        affichage += i;
        Console.WriteLine(affichage);
    }
    // option 2
    for (int i = 1; i <= 4; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            Console.Write(j);
        }
        Console.WriteLine();
    }
}
static void ex8c()
{
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 4 - i; j++)
        {
            Console.Write("#");
        }
        Console.WriteLine();
    }
}
static void ex8d()
{
    int nb = 0;
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            nb++;
            Console.Write(nb);
        }
        Console.WriteLine();
    }
}
static void ex8e()
{
    int nbParLigne = 0;
    for (int i = 1; i < 10; i++)
    {
        Console.WriteLine(i);
        nbParLigne++;
        if (nbParLigne == 3)
        {
            Console.WriteLine();
        }
    }
}