-
Notifications
You must be signed in to change notification settings - Fork 0
/
math_functions.o
73 lines (61 loc) · 1.69 KB
/
math_functions.o
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
int add(int a, int b);
int subtract_from_const(int n);
int multiply_by_const(int n);
double divide_by_const(int n);
double average(int size, int *array);
double area_of_circle(double radius);
int light_speed();
void chomp(char *string);
int my_strlen(char *string);
int my_strcmp(char *string1, char *string2);
// Sums two integers.
// Parameters: a, the first integer; b the second integer.
// Returns: the sum.
int add(int a, int b)
{
return a + b; // An inline comment.
}
// Subtracts an integer from a preprocessor defined constant.
// Parameters: n, the integer to subtract.
// Returns: the constant - n.
int subtract_from_const(int n)
{
return 100 - n;
}
// Multiplies an integer by a preprocessor defined constant.
// Parameters: n, the integer to multiply.
// Returns: the constant * n.
int multiply_by_const(int n)
{
return 50 * n;
}
// Divides an integer by a preprocessor defined constant.
// Parameters: n, the integer to divide.
// Returns: the constant / n.
double divide_by_const(int n)
{
return (double) 25 / n;
}
// Calculates the average of an array of integers.
// Parameters: size, the number of elements in the array; array, the array.
// Returns: the mean of the elements in array.
double average(int size, int *array)
{
int total = 0; // Store a running total.
for(int i=0; i<size; i++)
{
total += array[i];
}
return (double)total/size;
}
// Calculates the area of a circle.
// Parameters: radius, the radius of the circle.
// Returns: the area.
double area_of_circle(double radius)
{
return radius * radius * 3.142 ;
}
int light_speed()
{
return 299792458 ;
}