-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_stats.c
More file actions
67 lines (60 loc) · 1.24 KB
/
simple_stats.c
File metadata and controls
67 lines (60 loc) · 1.24 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
/* Computes some simple statistics on values entered by the user.
*
* Time spent: TODO
*
* Author(s): TODO
*/
#include <stdio.h>
#include <math.h>
int main(){
double num, min, max, arith, geo, count, harm;
geo = 1;
harm = 0;
int isPositive = 0;
int isNegative = 0;
printf("Please enter a number: ");
count = 0;
while(scanf("%lf", &num) == 1)
{
if(count == 0)
{
min = num;
max = num;
}
if(num <min)
{
min = num;
}
if(num > max)
{
max = num;
}
arith+=num;
geo*=num;
harm+=((1/num));
if(num>0)
{
isPositive++;
}
if(num<0)
{
isNegative++;
}
count++;
printf("Please enter a number: ");
}
harm = count/(harm);
arith/=count;
geo = pow(geo, 1/count);
printf("Min: %.2f", min);
printf(", Max: %.2f", max);
printf("\nArithmetic Mean: %.2f", arith);
if(isPositive == count || isNegative == count)
{
printf("\nGeometric Mean: %.2f", geo);
}
else{
printf("\nGeometric Mean: undefined");
}
printf("\nHarmonic Mean: %.2f", harm);
}