Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- int arr[5]; int key = 0; int j = 0;
- cout << "Enter the 5 numbers you want to sort!\n";
- for (int i = 0; i < 5; i++) {
- cin >> arr[i];
- }
- for (int i = 1; i < 5; i++)
- {
- key= arr[i];
- j = i- 1;
- while (j >= 0 && arr[j] > key) {
- arr[j + 1] = arr[j];
- j =j- 1;
- }
- arr[j + 1] = key;
- }
- for (int i = 0; i < 5; i++) {
- cout<< arr[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement