-
Notifications
You must be signed in to change notification settings - Fork 26
/
arrayAndFunction.c
58 lines (48 loc) · 1.72 KB
/
arrayAndFunction.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
#include <stdio.h>
/*
Your program should first read, from the user input, the number of players participating
in the game. There are never more than 10 players in the game. Next, your program should
read the current scores of each player and store them in an array. Then you should call the
function behind(), to which you pass as a first argument, the array holding the player's scores,
and as a second argument the number of players in the game. The function behind should replace
the scores stored in the array with the number of points by which each individual player is
behind the top-scoring player.
Example
Input
5
8 12 7 15 11
Output
7
3
8
0
4
*/
void behind(int *, int);
int main(void) {
int array[10];
int N, i;
scanf("%d", &N);
for (i=0; i<N; i++) {
scanf("%d", &array[i]);
}
behind(array, N);
for (i=0; i<N; i++) {
printf("%d\n", array[i]);
}
return 0;
}
/* Write your function behind() here: */
void behind(int * array, int N) {
int i, maxNum=0;
// find the maximum number
for (i=0; i<N; i++) {
if (array[i] > maxNum) {
maxNum = array[i];
}
}
//find the difference from maxNum
for (i=0; i<N; i++) {
array[i] = maxNum - array[i];
}
}