Questions 1 et 2
#include
using namespace std;
int main(int argc, char **argv)
{
int n;
int i = 0;
cout << "Entrer le premier nombre de la suite de Syracuse: ";
cin >> n;
while (n > 1) {
if (n % 2 == 0)
n /= 2;
else
n = n * 3 + 1;
i++;
cout << i << ": " << n << endl;
}
cout << "Suite terminee en " << i << " iterations." << endl;
return 0;
}
Question 3
#include
using namespace std;
int main(int argc, char **argv)
{
for (int j=1; j<=10; j++) {
int i = 0;
int n = j;
while (n > 1) {
if (n % 2 == 0)
n /= 2;
else
n = n * 3 + 1;
i++;
}
cout << n << ": " << i << " iterations." << endl;
}
return 0;
}Pages: 1 2