-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.c
83 lines (77 loc) · 2.1 KB
/
func.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//sorting array function using selection sort method
int *Sorting(int *array,int size){
int i,j,id,tmp;
for(i=0;i<size-1;i++){
id=i;
for(j=i+1;j<size;j++){
if(array[j]<array[id])
id=j;
}
tmp=array[id];
array[id]=array[i];
array[i]=tmp;
}
return array;
}
//mean using standard calculation
float Mean(int *array,int size){
int i;
float mean=0.0f;
for(i=0;i<size;i++)
mean=mean+array[i];
mean=mean/size;
return mean;
}
//mode calculation standard method
int Mode(int *array,int size){
int max_occur_val=0,max_occur_count=0,i,j;
array = Sorting(array,size);
for(i=0;i<size;i++){
int counter=0;
for(j=0;j<size;j++){
if(array[j]==array[i])
counter++;
}
if(counter>max_occur_count){
max_occur_count=counter;
max_occur_val=array[i];
}
}
return max_occur_val;
}
//median calculation using standard method
float Median(int *array,int size){
float median=0.0f;
array = Sorting(array,size);
if(size%2==0)
median=(array[(size-1)/2]+array[size/2])/2.0;
else
median=array[size/2];
return median;
}
//calculate maximum element linear search
int Maximum(int *array,int size){
int max=array[0],i;
for(i=1;i<size;i++){
if(max<array[i])
max=array[i];
}
return max;
}
//calculate minimum element linear search
int Minimum(int *array,int size){
int min = array[0],i;
for(i=1;i<size;i++){
if(min>array[i])
min=array[i];
}
return min;
}
//display function
void Display(int *array,int size){
int i=0;
printf("Array:\n");
for(i=0;i<size;i++)
printf("%d ",array[i]);
printf("\n");
}