Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int array[10]; // Declare array
- int end = 9; // Array holds 10 pieces of data
- for (int x = 0; x <= end; x++)
- {
- cin >> array[x]; // Read in array values
- }
- for (int times = 0; times <= end; times++) // Make n - 1 passes
- {
- for(int i = 0; i < end; i++) // For each element in array
- {
- if(array[i+1] < array[i]) // Compare 2 elements
- {
- int temp; // Temp variable to hold contents of i while we swap
- temp = array[i+1]; // Put smaller data in temporary holder
- array[i+1] = array[i]; // Put bigger number second
- array[i] = temp; // Put smaller number first
- }
- }
- }
- for (int y = 0; y <= end; y++)
- cout << array[y] << endl; // Print swapped array
- }
Advertisement
Add Comment
Please, Sign In to add comment