-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem04.c
More file actions
58 lines (49 loc) · 1.02 KB
/
problem04.c
File metadata and controls
58 lines (49 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
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
int getNoOfDays()
{
int n;
printf("Enter the no of days in the marathon (3-100): ");
scanf("%d", &n);
if (n < 3 || n > 100)
{
printf("Range exceed\n");
n = getNoOfDays();
}
return n;
}
void getScore(int n, int *scores)
{
printf("Enter the scores for each day: ");
for (int i = 0; i < n; i++)
{
scanf("%d", (scores + i));
}
return;
}
int checkMagicalDay(int n, int *scores)
{
int count = 0;
for (int i = 1; i < n - 1; i++)
{
if ((scores[i] > scores[i - 1]) && (scores[i] > scores[i + 1]))
count++;
}
return count;
}
int main()
{
int n;
n = getNoOfDays();
int *scores = (int *)malloc(n * sizeof(int));
if (scores == NULL)
{
printf("Memory allocation failed\n");
return 1;
}
getScore(n, scores);
int magicalDay = checkMagicalDay(n, scores);
printf("\nTotal no of magical days = %d\n", magicalDay);
free(scores);
return 0;
}