-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmeanmedmodediscrete.c
More file actions
89 lines (76 loc) · 1.95 KB
/
meanmedmodediscrete.c
File metadata and controls
89 lines (76 loc) · 1.95 KB
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
84
85
86
#include<stdio.h>
#include<conio.h>
void main()
{ int i;
int j; int n;
int p;
float array[15];
float temp;
float mean; float median; int mode;
printf("enter the number of values to enter");
scanf("%d",&n);
printf("enter the values in integer form:");
for(i=0;i<n;i++)
{
scanf("%f",&array[i]);
}
for(i=0;i<n-1;i++)
{
for(p=0;p<(n-i-1);p++)
{
if(array[p]>array[p+1])
{temp=array[p];
array[p]=array[p+1];
array[p+1]=temp;
}}
}
printf("sorted\n");
for(i=0;i<n;i++)
printf("%f ",array[i]);
if(n%2==0)
median=(array[(n/2-1)]+array[n/2])/2;
else{
median=array[(n+1)/2-1];}
printf("the median is %f\n",median);
int count[n];
for(i=0;i<n;i++)
{
int x=array[i];
count[i]=1;
for(j=0;j<i;j++)
{
if(array[j]==x)
count[i]++;
}
for(j=(i+1);j<n;j++)
{
if(array[j]==x)
count[i]++;
}
}
float sum=0;int maxpos=0;
for(i=0;i<n;i++)
{
sum+=array[i];
if(count[i]>count[maxpos])
maxpos=i;
}
if(count[maxpos]!=1)
{mode=array[maxpos];
printf("MODE: %f\n",array[maxpos]);
}
else
printf("no mode because each value occurs once\n");
mean=sum/n;
printf("mean is %f\n",mean);
float t;
float sd;
for(i=0;i<n;i++)
{
t+=pow(mean-array[i],2);
}
t/=n;
printf("%f\n",t);
sd=pow(t,0.5);
printf("\nstandard deviation of the data is =%f",sd);
}