C# :: Aufgabe #303 :: Lösung #4
6 Lösungen

#303
Häufigkeit einer 6 beim Würfeln?!
Anfänger - C#
von DragStar
- 06.04.2020 um 08:34 Uhr
Verfassen Sie ein Programm, welches 25.000 mal, jeweils so lange das Würfeln mit einem Würfel simuliert, bis eine 6 erscheint.
Auszugeben ist, wie oft man dabei schlimmstenfalls würfeln musste.
Auszugeben ist, wie oft man dabei schlimmstenfalls würfeln musste.
#4

von DavidDev024 (250 Punkte)
- 20.04.2020 um 16:48 Uhr

using System; namespace Wuerfel6 { class Program { private static Random rnd = new Random(); static void Main(string[] args) { int count = 0; int maxCount = 0; for(int i = 0; i < 25000; i++) { if (Wuerfel()) { if (count > maxCount) maxCount = count; count = 0; continue; } count++; } Console.Write("Maximale Anzahl die benoetigt wurde eine 6 zu wuerfeln: " + maxCount); Console.ReadKey(); } private static bool Wuerfel() { int augenZahl = rnd.Next(1, 7); if (augenZahl == 6) return true; return false; } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar
Seite 1 von 0
1