Code://gcc -W -Wall syracus.c -o s #include <stdio.h> #include <math.h> #include <stdlib.h> int question_1(int Up); int question_2(int Up); int question_3(int Un); int main() { int Up,Un; int A,B,C; FILE * fichier = NULL; fichier = fopen("neophytes.txt", "w"); if(fichier == NULL) { printf("Erreur de l'ouverture\n"); } else { printf("Overture reussie\n"); } if (fichier != NULL) { printf("Tapez le premier terme up : "); scanf("%d",&Up); A = question_1(Up,FILE); fputs("bonjour", fichier); } B = question_2(Up); Un = 0; C = question_3(Un); fclose(fichier); return EXIT_SUCCESS; } int question_1(int Up) { while(Up!=1) { if(Up%2==0) { Up=Up/2; fprintf(fichier,"%d ",Up); } else { Up=3*Up+1; fprintf(fichier,"%d ",Up); } } return Up; } int question_2(int Up) { int Max=-1; int a = 0; int suite = Up; int dva; while(Up!=1) { if(Up%2==0) { Up=Up/2; } else { Up=3*Up+1; } a++; if(Max<Up) { Max = Up; } if(suite>Up) { suite = 0; if(Up%2==0||Up%2==1) { dva=Up*2; } } } printf("\n"); printf("la durée de vol est:%d\n",a); printf("l'altitude est de :%d\n",Max); printf("la durée de vol en altitude est:%d\n",dva); return Up; } int question_3(int Un) { int dv1 = 0; int dv1_2; int Max = -1; int alt1,alt2; int dva,dva1,dva2; int un = 3; Un = un; int suite = Un; dv1_2 = 0; alt1 = 0; dva2 = 0; while(un<=99) { while(Un!=1) { if(Un%2==0) { Un=Un/2; } else { Un=3*Un+1; } dv1++; if(Max<Un) { Max = Un; alt2 = Max; } if(suite>Un) { suite = 0; if(Un%2==0||Un%2==1) { dva=Un*2; dva1 = dva; } } } if(dv1>dv1_2) { printf("Un=%d, est un noephyte de deuxiéme ordre\n",un); dv1_2 = dv1; } if(alt2>alt1) { printf("%d<%d --> ",alt1,alt2); printf("Un=%d, est un noephytes de troisieme ordre\n",un); alt1 = alt2; } if(dva1>dva2) { printf("%d<%d --> ",dva2,dva1); printf("Un=%d, est un noephytes de quatrieme ordre\n",un); dva2 = dva1; } un = un+2; Un = un; dv1 = 0; alt2 = 0; dva1 = 0; suite = un; } return Un; }
-----