A temperature sensor in an embedded system produces ADC result indices that correspond to fixed, known temperature values.
To avoid runtime computation, the firmware must store these values in a compile-time lookup table using constexpr.
Your task is to define such a lookup table and use it to convert an ADC index into the corresponding temperature.
What you must do:
constexpr array named TEMP_TABLE| ADC Index | Temperature (°C) |
| 0 | -40 |
| 1 | -10 |
| 2 | 20 |
| 3 | 50 |
| 4 | 80 |
| 5 | 120 |
constexprProgram input:
idx (range 0–5) representing the ADC result indexProgram output:
Example 1
Input:
3
Output:
50
Example 2
Input:
0
Output:
-40
Constraints:
constexpr
Input
0
Expected Output
-40