MrDj200

Sortierer

Mar 30th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdbool.h>
  4.  
  5. void main(void)
  6. {
  7.     int Anzahl, i, n, m, Zwischen;
  8.     char repeat;
  9.     bool switched;
  10.     double count = 0;
  11.     double count2 = 0;
  12.  
  13.     switched = false;
  14.  
  15.     system("cls");
  16.     system("color 0a");
  17.     system("title Sortierer");
  18.  
  19.     // Generieren von Zufallszahlen
  20.    printf("Anzahl der Zahlen, die sortiert werden sollen: ");
  21.    scanf("%d",&Anzahl);
  22.    int Zufall[Anzahl];
  23.  
  24.     printf("\nHier die %d Zufallszahlen:\n",Anzahl);
  25.     for(i=0; i<Anzahl; i++)
  26.     {
  27.         Zufall[i]= rand() % 100;
  28.         printf("%d  ",Zufall[i]);
  29.     }
  30.  
  31.  
  32.    while(!switched){
  33.  
  34.     switched = true;
  35.     for( i=0; i<=Anzahl; i++ ){
  36.  
  37.         count2 = count2 + 1.0;
  38.         if(Zufall[i]>Zufall[i+1]){
  39.             Zwischen    = Zufall[i];
  40.             Zufall[i]   = Zufall[i+1];
  41.             Zufall[i+1] = Zwischen;
  42.             switched = false;
  43.             count = count + 1.0;
  44.         }
  45.  
  46.     }
  47.    }
  48.  
  49.             printf("\n\nSortiert lauten die %d Zahlen:\n",Anzahl);
  50.             for(i=0; i<Anzahl; i++)
  51.             printf("%d  ",Zufall[i]);
  52.             printf("\n\nSo, das war's!!!\n");
  53.             printf("Es Wurde %0.f mal sortiert!\nEs Wurde %0.f mal verglichen!", count, count2);
  54.  
  55.             fflush(stdin);
  56.             printf("\n###########################\n");
  57.             printf("Wollen sie das Programm widerholen?[J/N]\n");
  58.             printf(">");
  59.             scanf("%c", &repeat);
  60.             repeat=tolower(repeat);
  61.             if(repeat=='j'){
  62.                 main();
  63.             }
  64.  
  65.             // Warten auf Tastendruck
  66.             system("PAUSE");
  67.  
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment