Bonsoir,

Question sûrement très bête mais l'algo ci-dessous me renvoie sans arrêt 0 parce qu'il semblerait que 2/3 renvoie la valeur 0...


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;
 
int main()
{
	int N = 10;
	double x;
	int i;
 
	cout << "Enter a starting point between -3 and 3" << endl;
	cin >> x;
 
	for (i = 1; i < N + 1; i++)
	{
		x = (2/3) *(1-x*x);
	}
 
	return x;
 
}
Quelqu'un peut-il m'expliquer ?
Normalement l'itération Xn+1 = (2/3) * (1-Xn²) devrait rester à -2 en fixant à x à -2 au départ. Et là ça passe à 0 directement.

D'avance merci