52. Constexpr ADC Temperature Table

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:

  • Create a constexpr array named TEMP_TABLE
  • The table must contain exactly 6 entries, mapped as follows:
  • ADC IndexTemperature (°C)
    0-40
    1-10
    220
    350
    480
    5120
  • You must declare this table yourself using constexpr

Program input:

  • Read an integer idx (range 0–5) representing the ADC result index

Program output:

  • Print the corresponding temperature value from the lookup table
  • No extra text

 

Example 1

Input:

3

Output:

50

 

Example 2 

Input:

0

Output:

-40 

 

Constraints:

  • The lookup table must be defined using constexpr
  • Runtime code must only read from the table — no computation allowed
  • Input is guaranteed to be within 0–5
  • Output must match exactly

 

 

 

 

Loading...

Input

0

Expected Output

-40