| 12
 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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 
 | #include <iostream>
using namespace std;
const int nmax=4;
const int mmax=8;
void permut (int &a, int &b);
void decompose (int nb, int t[],int &n);
void tri (int t[], int n);
void recsous (int t[], int n, int &result);
void affiche (int t[],int n);
 
int main()
{
    int nb,n=nmax,result,b=0,x,m=mmax,i;
    int t[nmax], tab[mmax];
    for (int i=0;i<m;i++)
    {
        tab[i]=0;
    }
 
    for (nb=1;nb<9999;nb++)
    {
        b=0;
        if (nb!=1111 && nb!=2222 && nb!=3333 && nb!=4444 && nb!=5555 && nb!=6666 
                && nb!=7777 && nb!=8888 && nb!=9999)
        {
            while (nb=!6174)
            {
 
                decompose (nb,t,n);
                tri (t,n);
                recsous (t,n,result);
                nb=result;
                b=b+1;
            }
            tab[b]=tab[b]+1;
 
        }
 
 
    }
    affiche (tab,m);
 
    system ("pause");
}
 
void permut (int &a, int &b)
{
    int aux;
    aux=a;
    a=b;
    b=aux;
}
void decompose (int nb, int t[],int &n)
{
    int i=0;
    for (i;i<n;i++)
    {
        t[i]=0;
    }
    i=0;
    while (nb!=0)
    {
        t[i]=nb%10;
        nb=nb/10;
        i++;
    }
}
void tri (int t[], int n)
{
    int i=0,j=0;
    for (i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(t[i]>t[j])
            {
                permut (t[i],t[j]);
            }
        }
    }
}
void recsous (int t[], int n, int &result)
{
    int i=0,nb1=0,nb2=0,p=1;
    for (i;i<n;i++)
    {
        nb1=t[i]*p+nb1;
        nb2=t[n-i-1]*p+nb2;
        p=p*10;
    }
    result=nb1-nb2;
}
void affiche (int t[],int n)
{
    cout<<"Voila le tableau"<<endl;
    for (int i=0;i<n;i++)
    {
        cout<<t[i]<<endl;
    }
} | 
Partager