#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define ANTAL 100
#define RANGE 500

void randGen(int arr[]){
  srand(time(NULL));
  int i;
  for (i = 0; i < ANTAL; i++)
    {
      arr[i] = rand() % RANGE;
    }
}

void sort(int arr[]){
  int top = 1;
  int bottom = 0;
  int count = 0;
  int i, j, tmp;
  for (j = 0; j < ANTAL; j++)
    {
      
      for (i = 0 + bottom; i < ANTAL - 1; i++)
	{
	  count++;
	  if (arr[i] < arr[i + 1])
	    {
	      tmp = arr[i + 1];
	      arr[i + 1] = arr[i];
	      arr[i] = tmp;
	    }
	}
      top++;
    }
  printf("No of cycles: %d\n", count);
}

int main () {

  int arr[ANTAL];

  randGen(arr);
  sort(arr);

  int i;
  for (i = 0; i < ANTAL; i++)
    {
      printf("%i\n", arr[i]);
    }


  return 0;

}
