È dato il seguente programma:
#includeint f[10]; int i; int main() { f[0]=5; f[1]=3; for(i=0; i < 8; i++) f[i+2]=f[i+1]-f[i]; for(i=0; i < 10; i++) printf("%d, ", f[i]); } Cosa viene visualizzato a video?
- 5, 3, -2, -5, -3, 2, 5, 3, -2, -5,
- 5, 3, 5, 3, 5, 3, 5, 3, -2, -5,
- -5, -3, -2, -5, -3, 2, 5, 3, -2, -5,
- 5, 3, 2, 5, -3, 2, 5, 3, -2, -5,
Soluzione: d (5 3 -2 -5 -3 2 5 3 -2 -5)
Prima del for
5 3 0 0 0 0 0 0 0 0
I passi del for
- 3-5 = -2, 5 3 -2 0 0 0 0 0 0 0
- -2-3 = -5, 5 3 -2 -5 0 0 0 0 0 0
- -5-(-2) = -3, 5 3 -2 -5 -3 0 0 0 0 0
- -3-(-5) = 2, 5 3 -2 -5 -3 2 0 0 0 0
- 2-(-3) = 5, 5 3 -2 -5 -3 2 5 0 0 0
- 5-2 = 3, 5 3 -2 -5 -3 2 5 3 0 0
- 3-5 = -2, 5 3 -2 -5 -3 2 5 3 -2 0
- -2-3 = -5, 5 3 -2 -5 -3 2 5 3 -2 -5