Answer to Question #100833 in C++ for zahra

Question #100833
Write a program that asks the user to enter an array of random numbers,then sort the numbers
(ascending order),then print the new array,after that asks the user for a new two numbers and add them to the same array and keep the array organization. solve with while
1
Expert's answer
2020-01-02T11:30:48-0500

#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;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS