Farming God

Farming God

  • NA
  • 2
  • 540

How can I get this 6 for loop done with recursive programmin

Jan 23 2019 3:35 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1.Methoden
{
/*
* In dieser Klasse
* werden alle möglichen
* Kombinationen für das
* Spiel: Lotto 6 aus 49
* aufgelistet
*/
class AlleKombinationen
/* Werte bestimmen */
static int zaehler = 0;
static string neuer_zaehler;
static int max_kombinationen = 13983816;
static int ErsteZahl = 45;
static int ZweiteZahl = 46;
static int DritteZahl = 46;
static int VierteZahl = 48;
static int FünfteZahl = 49;
static int SechsteZahl = 50;
class Lotto
{
public void AlleKombinationenAusgeben()
{
Console.Title = "Lotto: 6 aus 49";
/* Try-Catch Block */
try
{
for (int a = 1; a < ErsteZahl; a++)
{
for (int b = a + 1; b < ZweiteZahl; b++)
{
for (int c = b + 1; c < DritteZahl; c++)
{
for (int d = c + 1; d < VierteZahl; d++)
{
for (int e = d + 1; e < FünfteZahl; e++)
{
for (int f = e + 1; f < SechsteZahl; f++)
{
zaehler++;
neuer_zaehler = zaehler.ToString("N0");
Console.WriteLine(a + " " + b + " " + c + " " + d + " " + e + " " + f + " | -> " + neuer_zaehler);
if (zaehler == max_kombinationen)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Es wurden {neuer_zaehler} Kombinationen wurden erstellt!");
Console.ReadKey();
}
}
}
}
}
}
}
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Fehler: " + ex);
Console.ReadKey();
}
}
}
/* Hauptteil des Programmes */
public static void main()
{
/// <summary>
/// Beschreibung
/// </summary>
Lotto AlleKombinationen = new Lotto();
/// <summary>
/// Alle Kombinationen ausgeben lassen
/// </summary>
AlleKombinationen.AlleKombinationenAusgeben();
}
}
}
 This is my code.
How can I get the 6 for loops done with recursive?
I heard it's possible.. but I dont know where I should start :/ 

Answers (1)