since no one replied to my first posting I am trying again. This time I was able to take a set length (4) number and sort its digits in order. Example make 5961 output 1659. Can anyone tell me how to do this without limiting the length of the number?
Please help
Dale
#include <iostream>
using namespace std;
void main()
{
int num;
int digit1, digit2, digit3, digit4;
int rem1, rem2, rem3, rem4;
int temp;
cout << "Please enter a 4 digit number: ";
cin >> num;
rem4 = num % 10;
rem3 = num % 100;
rem2 = num % 1000;
rem1 = num % 10000;
digit4 = rem4;
digit3 = rem3/10;
digit2 = rem2/100;
digit1 = rem1/1000;
int array[]={digit1, digit2, digit3, digit4};
for(int i=0; i<4-1;i++)
for(int j=i+1; j<4;j++)
if(array[i]>array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
cout<<"\nthe sorted array is: ";
for(i=0; i<4; i++)
cout<<array[i];
cout<<"\n";
}