-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem03.c
More file actions
38 lines (31 loc) · 846 Bytes
/
Copy pathproblem03.c
File metadata and controls
38 lines (31 loc) · 846 Bytes
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
#include <stdio.h>
#include <stdlib.h>
void getVehicleNo(int n, int *vehicles){
for (int i = 0; i < n; i++)
scanf("%d", (vehicles + i));
return;
}
int checkJamHour(int n, int *vehicles){
int count = 0;
for (int i = 1; i < n; i++){
if (*(vehicles + i) >= 50 && (*(vehicles + i) > *(vehicles + i - 1)))
count++;
}
return count;
}
int main(){
int n;
printf("Enter the total no of hours: ");
scanf("%d", &n);
int *vehicles = (int *)malloc(n * sizeof(int));
if (vehicles == NULL){
printf("Memory allocation failed");
return 1;
}
printf("Enter the no of vehicles for each hour:");
getVehicleNo(n, vehicles);
int jamHour = checkJamHour(n, vehicles);
printf("Total Critical Jam Hour = %d", jamHour);
free(vehicles);
return 0;
}