-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmath_functions.c
68 lines (59 loc) · 1.47 KB
/
math_functions.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
#include "math_functions.h"
#define X 100
#define Y 50
#define Z 25
#define PI 3.142
#define E 2.71828
#define SPEED_OF_LIGHT 299792458
#include "string_functions.h"
// 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 X - 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 Y * 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) Z / 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 * PI ;
}
int light_speed()
{
return SPEED_OF_LIGHT ;
}