Guest User

Untitled

a guest
Jan 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>   //Implementieren des Headers time.h
  4. #include <conio.h>
  5.  
  6.  
  7. int main()
  8. {
  9.     int pool[7]= {0,0,0,0,0,0,0};
  10.     int anzahl;
  11.     int zufallszahl;
  12.     int k,x,z,i,j,v,b,t,c;
  13.     int tmp;
  14.     int neuezahl;
  15.     int eingabe[7];
  16.  
  17.  
  18.     printf("Dieses Programm simuliert ein Lottospiel!");
  19.     printf("\n-----------------------------------------\n");
  20.  
  21.     printf("\nBitte geben Sie nun Ihre 6 Wunschzahlen, zwischen 1-49 ein (keine doppelten Zahlen!):\n");
  22.     for(b=0; b<=5; b++)
  23.     {
  24.         printf("\nWunschzahl %i: ",b+1);
  25.         scanf("%i",&eingabe[b]);
  26.  
  27.  
  28.     }
  29.  
  30.     printf("\n\n\n");
  31.  
  32.     srand(time(NULL));
  33.     {
  34.         for(anzahl=1; anzahl<7; anzahl++)
  35.  
  36.         {
  37.             printf("Zahl %i\t",anzahl);
  38.         }
  39.  
  40.         printf("Zusatzzahl");
  41.         printf("  \tGewinnzahlen pro Reihe");
  42.  
  43.         printf("\n");
  44.  
  45.         for(x = 1; x <=6; x++)
  46.         {
  47.             printf("\n");
  48.             for (k=0; k<7; k++)
  49.             {
  50.                 zufallszahl=rand()%49+1;
  51.                 for(v=0; v<7; v++)
  52.                 {
  53.                     if(pool[v]==zufallszahl)
  54.                     {
  55.                         zufallszahl=rand()%49+1;
  56.                     }
  57.                 }
  58.                 pool[k]=zufallszahl;
  59.  
  60.             }
  61.  
  62.             for (i = 0; i < 7 -1; ++i)
  63.             {
  64.                 for (j = 0; j < 7 - i - 1; ++j)
  65.                 {
  66.                     if (pool[j] > pool[j + 1])
  67.                     {
  68.                         int tmp = pool[j];
  69.                         pool[j] = pool[j + 1];
  70.                         pool[j + 1] = tmp;
  71.                     }
  72.                 }
  73.             }
  74.  
  75.  
  76.             for(z=0; z<7; z++)
  77.             {
  78.  
  79.                 printf("%i\t",pool[z]);
  80.  
  81.             }
  82.  
  83.  
  84.             printf("\t  ");
  85.             for(t=0; t<7; t++)
  86.             {
  87.                 for(c=0; c<7; c++)
  88.                 {
  89.  
  90.                     if(pool[t]==eingabe[c])
  91.                     {
  92.                         printf(" *%i",pool[t]);
  93.                     }
  94.                 }
  95.  
  96.  
  97.             }
  98.  
  99.         }
  100.  
  101.  
  102.     }
  103.  
  104.  
  105.  
  106.     getch();
  107.     return(0);
  108.  
  109. }
  110.  
  111.  
  112. /*
  113.  Aufgaben zur Optimierung:
  114.  
  115. -> Setze bitte zunächst diesen Algorithmus in deinem Lottoprogramm um:
  116. „Korrekt wäre also tatsächlich die Zahlen von 1-49 vorzuhalten, eine Zufallszahl zu generieren und diese dann vor dem nächsten Durchlauf aus dem Zahlenvorrat zu entfernen.“
  117.  
  118.  
  119. -> fehlende Eingabeprüfung einbringen!
  120.  
  121. -> Das Programm sollte nicht pro Zeile die Treffer ausgeben, sondern am Ende die Treffer aus der Zeile mit den meisten Treffern.
  122.  
  123. */
Add Comment
Please, Sign In to add comment