/***********************************************\
* Autor: Stefan Ruemmele / Zeiner (Kommentare)  *
* Zweck: Loesung einer Pruefungsaufgabe         *
* Datei: wuerfeln.c                             *
\***********************************************/

#include        /* fuer rand()  */
#include <stdio.h>

#define N 1000   /* maximale Anzahl der Zufallszahlen */
#define ZMAX 6   /* groesste Zufallszahl              */

void zufall(int vektor[], int n)
{
  int i;

  for(i = 0; i < n; i++) {
    vektor[i] = rand() % ZMAX + 1; /* ermittelt eine Zufallszahl
*/
  }     /* zwischen 1 und ZMAX        */
}

void haeufigkeit(int v[], int n, int h[])                 /*
------------------------------------------------------------
ermittelt, wie oft die Zahlen 1 bis 6 im Vektor v vorkommen,
das Resultat wird im Vektor h bei Index 1 bis 6 abgelegt,
Index 0 wird nicht verwendet
------------------------------------------------------------*/

{
  int i, j;

  for(i = 1; i <= ZMAX; i++) {
    h[i] = 0;
    for(j = 0; j < n; j++)
      if(v[j] == i)
        h[i]++;
  }

  /* 
     eine andere Loesung waere, da sicher ist,
     dass v nur Zahlen zwischen 1 und 6 enthaelt:  
  */

  /*
     for (i = 1; i <= ZMAX; i++) h[i] = 0;
     for (i = 0; i < n; i++)
       h[v[i]]++;
  */

}

int main(void)
{
  int i, n;
  int zufallszahlen[N], wieoft[ZMAX+1];

  printf("\nWuerfeln durch Zufallszahlenerzeugung: Wie oft?
(max. %3i) ", N);
  scanf("%i%*c", &n);
  zufall(zufallszahlen, n);   /* erzeugt die Zufallszahlen */

  haeufigkeit(zufallszahlen, n, wieoft);
  printf("\nZahl\tH"ufigkeit\n");
  printf("------------------\n");
  for(i = 1; i <= ZMAX; i++)
    printf(" %1i\t  %3i\n", i, wieoft[i]);

  getchar();
  return 0;
}




/* ----------------------------------------------------------*\
*  Dateiname: lotto.c
*  Zweck: Zweiter Ainf-Test
*  Version: 1.0
*
*  Autor: Stefan Bischof
*  Datum: 29.1.1999
\* -----------------------------------------------------------*/

#include <stdio.h>
#include 
#include 
#define TRUE 0
#define FALSE 1

int zufall (void)
{
   return rand() % 45 + 1;
}

void vinit (char vektor[])
{
   int i;
   for (i = 1; i < 46; i++)
      vektor[i] = '-';
}

void lotto (char vektor [], int zahl[])
{
   int i;
   int doppelt;

   srand( (unsigned) time(NULL) % 100);

   for (i = 0; i < 6; i++)
   {
      do
      {
  doppelt = FALSE;
  zahl [i] = zufall();
  if (vektor[zahl[i]] == '*')
  doppelt = TRUE;
      } while (doppelt == TRUE);
      vektor[zahl[i]] = '*';
   }
}

int main (void)
{
   char auswahl[46];
   int zahlen[6];
   int i;

   vinit (auswahl);
   lotto (auswahl, zahlen);

   printf ("\nLottozahlengenerator 6 aus 45:\n\n");

   printf ("Mein Lottotip: ");
   for (i = 0; i < 6; i++)
      printf ("%3d", zahlen[i]);

   printf("\n\nEnde mit Eingabetaste!");
   getchar();

   return 0;
}