Advertisement
Guest User

Untitled

a guest
Mar 4th, 2013
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void PrintArray(int a[], int size)
  6. {
  7. for( int i = 0; i < size-1; i++ )
  8. cout << setw(2) << a[i] << ",";
  9. cout << setw(2) << a[size-1] << endl;
  10. }
  11.  
  12. int arrayVals;
  13. int num[100];
  14. int i = 0;
  15. int arrayPos = 0;
  16. int main( )
  17. {
  18. cout << "This program sorts a set of numbers." << endl;
  19. cout << endl << "How many values? ";
  20. cin >> arrayVals;
  21. while ( i < arrayVals )
  22. {
  23. cin >> num[i];
  24. i++;
  25. }
  26.  
  27. int minVal = num[0];
  28. int minPos = 0;
  29. cout << endl;
  30. while ( arrayPos < arrayVals-1 )
  31. {
  32. i = arrayPos;
  33. while ( i < arrayVals )
  34. {
  35. if ( num[i] <= minVal )
  36. {
  37. minVal = num[i];
  38. minPos = i;
  39. }
  40. i++;
  41. }
  42. num[minPos] = num[arrayPos];
  43. num[arrayPos] = minVal;
  44. PrintArray(num , arrayVals);
  45. arrayPos++;
  46. minVal = num[arrayPos];
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement