Bonjour,
je tente d'utiliser des boucles (for, while), mais cela donne des comportement imprévisibles.
voici un exemple :
et voici le résultat (pour le moins surprenant) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <iostream> #include <stdio.h> using namespace std; int main() { cout << "Hello world!" << endl; int position = 5; for (int i = 0; i<5; i++) { position += i; printf ("i = %d, position (%d+5) = %d\n", i, i, position); } return 0; }
Si quelqu'un peut m'expliquer ce phénomène et surtout comment obtenir quelque chose de plus classique.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 Hello world! i = 0, position (0+5) = 5 i = 1, position (1+5) = 6 i = 2, position (2+5) = 8 i = 3, position (3+5) = 11 i = 4, position (4+5) = 15 Process returned 0 (0x0) execution time : 0.030 s Press any key to continue.
Merci d'avance
Partager