944,171 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1836
  • C++ RSS
Dec 8th, 2004
0

print a number in ordered form

Expand Post »
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?
C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dowens3rd is offline Offline
7 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help with getting soda machine program running
Next Thread in C++ Forum Timeline: Need help with a function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC