Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <stdbool.h>
- void main(void)
- {
- int Anzahl, i, n, m, Zwischen;
- char repeat;
- bool switched;
- double count = 0;
- double count2 = 0;
- switched = false;
- system("cls");
- system("color 0a");
- system("title Sortierer");
- // Generieren von Zufallszahlen
- printf("Anzahl der Zahlen, die sortiert werden sollen: ");
- scanf("%d",&Anzahl);
- int Zufall[Anzahl];
- printf("\nHier die %d Zufallszahlen:\n",Anzahl);
- for(i=0; i<Anzahl; i++)
- {
- Zufall[i]= rand() % 100;
- printf("%d ",Zufall[i]);
- }
- while(!switched){
- switched = true;
- for( i=0; i<=Anzahl; i++ ){
- count2 = count2 + 1.0;
- if(Zufall[i]>Zufall[i+1]){
- Zwischen = Zufall[i];
- Zufall[i] = Zufall[i+1];
- Zufall[i+1] = Zwischen;
- switched = false;
- count = count + 1.0;
- }
- }
- }
- printf("\n\nSortiert lauten die %d Zahlen:\n",Anzahl);
- for(i=0; i<Anzahl; i++)
- printf("%d ",Zufall[i]);
- printf("\n\nSo, das war's!!!\n");
- printf("Es Wurde %0.f mal sortiert!\nEs Wurde %0.f mal verglichen!", count, count2);
- fflush(stdin);
- printf("\n###########################\n");
- printf("Wollen sie das Programm widerholen?[J/N]\n");
- printf(">");
- scanf("%c", &repeat);
- repeat=tolower(repeat);
- if(repeat=='j'){
- main();
- }
- // Warten auf Tastendruck
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment