1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 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; } |
- Tuesday
- April 8th, 2025
- Ajouter un cours