-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2_max.c
More file actions
46 lines (38 loc) · 1.02 KB
/
2_max.c
File metadata and controls
46 lines (38 loc) · 1.02 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
/* ***************************************************************************
* Author : Kura Peng (kpeng) <https://github.com/sayakura>
* Created : 2018/10/05
* Updated : 2018/10/05
* ***************************************************************************/
int max(int* tab, unsigned int len)
{
if (!tab)
return (0);
int max = tab[0];
for (unsigned int i = 0; i < len; i++)
{
if (tab[i] > max)
max = tab[i];
}
return (max);
}
/*------------------------------------------------------------------
#include <stdio.h>
int main()
{
int tab[] = {34};
printf("%d\n", max(tab, 1));
return (0);
}
*/
/*
Assignment name : max
Expected files : max.c
Allowed functions:
--------------------------------------------------------------------------------
Write the following function:
int max(int* tab, unsigned int len);
The first parameter is an array of int, the second is the number of elements in
the array.
The function returns the largest number found in the array.
If the array is empty, the function returns 0.
*/