25. tétel: Véletlen csillagok

Feladat: A szöveges képernyőre egy 80x25-ös téglalapon belül rajzoljon fel véletlenszerűen 111 piros és 111 kék színű csillagot!
A működő programot és a kódot mutassa be tanárának!

Egy lehetséges megoldás Visual C# nyelven:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 25tetel
{
    class Program
    {
        static void Main(string[] args)
        {
            //25. tétel: Véletlenszerű csillagok
            const string csillag = "*";
            Console.Clear();		//Ez a képernyőtörlés
            Console.ForegroundColor = ConsoleColor.Red;
            Random r1 = new Random();
            for (int i = 0; i < 222; i++)
            {
                Console.SetCursorPosition(r1.Next(0, 80), r1.Next(0, 25));
                Console.Write(csillag);
                if (i==111)
                {
                    Console.ForegroundColor = ConsoleColor.Blue;
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(0, 24);
            Console.WriteLine("\n\nA program futása véget ért!");
        }
    }
}