/* LightCollege.ir Learn C Programing*/
#include<stdio.h>
#include<stdlib.h>

#define SIZE 600

void ArrPrint(int arr[],int size);
void FillArray(int n[],int size);
void bubbleSort(int n[],int size);

void main(){
	int arr[SIZE];
	FillArray(arr,SIZE);
	ArrPrint(arr,SIZE);
	printf("After Sort : ");
	bubbleSort(arr,SIZE);
	ArrPrint(arr,SIZE);
	
	// miangin
	int i,sum=0;
	for(i=0;i<SIZE;i++){
		sum += arr[i];
	}
	int rslt = sum/SIZE;
	printf("\nMid : %d",rslt);
	
	if(SIZE % 2 == 0){
		rslt = arr[SIZE/2];
	}
	else{
		rslt = arr[SIZE/2] + arr[(SIZE/2)+1];
		rslt = rslt/2;
	}
	printf("\nMedian : %d",rslt);
	
	//mode
	int c[100];
	for(i=0;i<SIZE;i++){
		c[i] = 0;
	}
	for(i=0;i<SIZE;i++){
		c[arr[i]]++;
	}
	rslt = 0;
	int max = 0;
	for(i=0;i<SIZE;i++){
		if(c[i] > max){
			max=c[i];
			rslt = i;
		}
	}
	printf("\nMode is %d (%d times)",rslt,max);
}

void bubbleSort(int n[],int size){
	int i,j;
	for(i=0;i<size;i++){
		/* sort */
		for(j=0;j<size-1-i;j++){
			if(n[j] > n[j+1]){
				int hold = n[j];
				n[j] = n[j+1];
				n[j+1] = hold;
			}
		}
		/* end sort */
	}
}

void FillArray(int n[],int size){
	int i;
	for(i=0 ; i< size ; i++){
		n[i] = rand() % 101;
	}
}

void ArrPrint(int arr[],int size){
	printf("\n");
	int i;
	for(i=1;i<=size;i++){
		printf("%8d",arr[i-1]);
		if(i%10 == 0)printf("\n");
	}
	printf("\n");
}

/*power by LightCompany.ir*/
