-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_sum.c
executable file
·54 lines (51 loc) · 1.64 KB
/
ft_sum.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <akharrou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/16 21:28:40 by akharrou #+# #+# */
/* Updated: 2019/03/16 23:31:28 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** ft_sum -- sum a sequence of numbers.
**
** SYNOPSIS
** #include "math_42.h"
**
** int
** ft_sum(int *vector, unsigned int size);
**
** PARAMETERS
**
** int *vector Vector of numbers (of type int)
** that are to be summed.
**
** unsigned int Size of the vector.
**
** DESCRIPTION
** Iterates through the vector summing up the numbers contained in it
** along the way.
**
** RETURN VALUES
** Returns the sum of all the numbers in the vector.
*/
int ft_sum(int *vector, unsigned int size)
{
unsigned int i;
int sum;
sum = 0;
if (vector && size > 0)
{
i = 0;
while (size > i)
{
sum += vector[i];
++i;
}
}
return (sum);
}