#include void decomp3(int val, int* centaine, int* dizaine,int* unite){ *centaine = val/100; val = val - ((*centaine)*100); *dizaine = val/10; val = val - ((*dizaine)*10); *unite = val; } int recomp3( int centaine, int dizaine,int unite){ return centaine*100+dizaine*10+unite; } void permuter (int* a, int* b){ int tmp; tmp = *a; *a = *b; *b = tmp; } void MaxMin(int* v1,int* v2){ if(*v2>*v1){ permuter(v1,v2); } } void ordonne3 (int*a, int*b, int*c){ MaxMin(a,b); MaxMin(b,c); MaxMin(a,b); } void ordonne3croissant (int*a, int*b, int*c){ MaxMin(a,b); MaxMin(b,c); MaxMin(a,b); permuter(a,c); } int calcNbr(int val){ int centaine, dizaine, unite; int N1, N2, NBR; decomp3(val,¢aine,&dizaine,&unite); ordonne3(¢aine,&dizaine,&unite); N1=recomp3(centaine, dizaine, unite); ordonne3croissant(¢aine,&dizaine,&unite); N2=recomp3(centaine, dizaine, unite); NBR=N1-N2; return NBR; } int convergence(int val){ int valSave=val; int NBR; NBR = calcNbr(val); while(valSave != NBR){ valSave = NBR; NBR = calcNbr(NBR); //printf("%d\n",NBR); } return NBR; } int main(){ int val,NBR; scanf("%d",&val); NBR = convergence(val); printf("Nombre: %d Convergence: %d \n",val, NBR); /*int N1, N2, NBR; decomp3(val,¢aine,&dizaine,&unite); ordonne3(¢aine,&dizaine,&unite); N1=recomp3(centaine, dizaine, unite); ordonne3croissant(¢aine,&dizaine,&unite); N2=recomp3(centaine, dizaine, unite); NBR=N1-N2; //printf("Valeur initiale: %d \n N1: %d \n N2: %d \n NBR: %d\n",val,N1,N2,NBR); */ return 0; }