C programming · Lesson
Close the path by building and verifying a complete solution: data, loop, conditions, arrays, statistics, tests and a final decision.
The project uses five temperature readings. It reads a threshold, computes average, minimum and maximum, counts how many readings reach the threshold, and produces ALERT or OK. Solution quality is checked with multiple tests, not a single run.
specification → array → threshold → loop → statistics → ALERT/OK → tests: 22→5 ALERT | 30→2 ALERT | 35→1 ALERT | 36→0 OK
Use Start and Step: when the active block changes, ConceptStep also highlights the C lines representing that same step.
Run C executes only the example shown on the left, using stdin on the right. The coding challenge below has a separate editor and test button.
1#include <stdio.h>
2
3int main(void)
4{
5 int temperature[5] = {22, 24, 31, 28, 35};
6 int soglia;
7 scanf("%d", &soglia);
8
9 int somma = 0;
10 int minimo = temperature[0];
11 int massimo = temperature[0];
12 int oltre = 0;
13
14 for (int i = 0; i < 5; i = i + 1)
15 {
16 somma = somma + temperature[i];
17
18 if (temperature[i] < minimo)
19 minimo = temperature[i];
20
21 if (temperature[i] > massimo)
22 massimo = temperature[i];
23
24 if (temperature[i] >= soglia)
25 oltre = oltre + 1;
26 }
27
28 int media = somma / 5;
29 printf("%d\n", media);
30 printf("%d\n", minimo);
31 printf("%d\n", massimo);
32 printf("%d\n", oltre);
33
34 if (oltre > 0)
35 printf("ALLERTA\n");
36 else
37 printf("OK\n");
38
39 return 0;
40}
Read five integer temperatures and a threshold; print how many meet or exceed it.
This is a different program from lab 1. Complete the starter code: Check all test cases compiles this editor and tests every input, including boundary cases.
With temperatures 22, 24, 31, 28, 35 and threshold 36, what final status should the program produce?
Challenge 1 / 5 · Understanding
Progress: 0 / 5 · correct: 0
ConceptStep separates what is required from what is recommended or useful as reinforcement. Only required prerequisites block your progress.
Relationships: solid line = required · dashed line = recommended · dotted line = reinforcement.