vendredi 6 novembre 2020

is there anyone who can help me with the problem i'm facing?

i wanted to do patterns using while loop but i don't seem to understand it quite well, can i please be assisted on this matter please. patters i wanted to do are: diamond shape using while loop C# asterics, triangle, hollow triangle and hollow rectangle shape. thank you. All of them can the be in c# please.

int number = 7;

    for (int i = 0; i < number; i++)
    {
        if (i == 0 || i == 6)
        {
            for (int j = 0; j < number; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
        if (i >= 1 && i <= 5)
        {
            for (int j = 0; j < number; j++)
            {
                if (j == 0 || j == 6)
                {
                    Console.Write("*");
                }
                else if (j >= 1 && j <= 5)
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();

this i what i tried.

Aucun commentaire:

Enregistrer un commentaire