#include <iostream>
using namespace std;
int main()
{
int n = 20, i = 0, j, key;
cout << "How many numbers you want to input > ";
cin >> n;
int *arr = new int[n + 2];
cout << "Enter " << n++ << " number\n";
cin >> arr[i++];
while(n--){
cin >> arr[i];
key = arr[i];
j = i - 1;
while(j >= 0 && arr[j] > key){
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
i++;
if(n == 2){
for(int x=0; x<i; cout << arr[x++] << " ");
cout << "\nEnter new two numbers\n";
}
}
for(int x=0; x<i; cout << arr[x++] << " ");
cout << endl;
delete [] arr;
}
Comments
Leave a comment