print a number in ordered form

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2004
Posts: 7
Reputation: dowens3rd is an unknown quantity at this point 
Solved Threads: 0
dowens3rd dowens3rd is offline Offline
Newbie Poster

print a number in ordered form

 
0
  #1
Dec 8th, 2004
I am being asked to take a number like 86249 and produce the output 24689. Basically take a number and print it in ordered form. I can do this with an array of multiple numbers, but can't figure out how to split the number entered into an array so this can be done. Am I following the right logic or am I way off base?
  1. #include<iostream.h>
  2.  
  3. void main()
  4. {
  5. int arr[50];
  6. int size, temp;
  7. do{
  8. cout<<"Enter the size of the array(max 50): ";
  9. cin>>size;
  10. }while(size>50 || size <1);
  11. cout<<"\nEnter the values: ";
  12. for(int i=0; i<size; i++)
  13. cin>>arr[i];
  14. for(i=0; i<size-1;i++)
  15. for(int j=i+1; j<size;j++)
  16. if(arr[i]>arr[j])
  17. {
  18. temp=arr[i];
  19. arr[i]=arr[j];
  20. arr[j]=temp;
  21. }
  22. cout<<"\nthe sorted array is: ";
  23. for(i=0; i<size; i++)
  24. cout<<arr[i];
  25. cout<<"\n";
  26. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1723 | Replies: 0
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC