Tre quesiti di programmazione del 2017 tradotti nel nuovo pseudocodice
2017 – n. 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function FUN(p: integer) → integer output p, " -› " if p MOD 2 = 0 then output "condizione 1" end if if p = 7 then output "condizione 2" else if (p-5) MOD 2 = 0 then output "condizione 3" end if end if return p end function |
Quale delle seguenti affermazioni è errata?
- La funzione, se p è pari, scrive a video il valore di p seguito dalla stringa -> condizione 1 e restituisce p
- La funzione, se p non è dispari, scrive a video il valore di p seguito dalla stringa -> condizione 2 e restituisce p
- La funzione, se p è 7, scrive a video il valore di p seguito dalla stringa -> condizione 2 e restituisce p
- La funzione, se p è dispari, scrive a video p seguito dalla stringa -> condizione 2 o -> condizione 3 e restituisce p
2017 – n. 7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
variable x: integer variable y: integer variable a: integer variable p: integer variable l: float variable d: float x ← 20 y ← 10 a ← x × y p ← 2 × x + 2 × y l ← p/4 d ← RADICEQUADRATA(2) × l output d, " cm" if d × 2 - 720 = 0 then d ← 2 else d ← 1 end if |
Cosa viene visualizzato a video dall’esecuzione del programma qui sopra?
- 2.000000 cm
- 3.000000 cm
- 21.213203 cm
- 36.243204 cm
2017 – n. 8
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function MYSTER(c: integer, d: integer) → integer if c = d then return c end if if c › d then return MYSTER(c-d, d) end if return MYSTER(c, d-c) end function function MCM(a: integer, b: integer) → integer return MYSTER(b, a) end function |
Quale delle seguenti modifiche fa sì che la funzione mcm ritorni il minimo comune multiplo tra a e b?
- sostituire MYSTER(b, a) con MYSTER(a, b)
- sostituire MYSTER(b, a) con (a × b)/MYSTER(b, a)
- sostituire MYSTER(b, a) con MYSTER(a-b, b)
- sostituire MYSTER(b, a) con MYSTER(a, b-a)