how to sort the digits of an integer without using array?

void sortDigits(int x){
for ( int l = 0; l < 10; ++l )
{
int rem = x % 10;
int tx = x / 10;
while ( tx != 0 )
{
if ( rem == l ) cout << rem;
rem = tx % 10;
tx = tx / 10;
}
}
}

1 comment:

  1. //slight correction
    #include

    using namespace std;

    int main()
    {
    int rem, tx;
    int x = 338197013;
    for (int l = 0; l < 10; ++l)
    {

    tx =x;
    while (tx > 0)
    {
    rem = tx % 10;
    tx = tx / 10;
    if (rem == l)
    cout << rem;

    }
    }
    return 0;
    }

    ReplyDelete