Write a C++ program that has an array of integers. The maximum size of the array is 100. The program should ask the user to enter the number of elements to be stored in the array, then the program should ask the user to enter that many numbers to be stored in the array as they are entered.
((The program should call a function (putInOrder) to rearrange the numbers stored in the array such that they are stored in the array in increasing order)).
The function putInOrder takes as input the address of the array and the number of elements in the array.
how cuold i write a code to sort the numbers of array in order "starting from smaller number to the begest number??
To answer the question would defeat the purpose of the assignment. But let me point out a big something: What algorithm do you need to use? Bubble sort? Quicksort? Merge sort? First decide on the algorithm, then attempt to code this. Then ask questions if you get stuck.
#include <iostream>
usingnamespace std;
void putInOrder (int,int& ); // to rearrange the number
int main ()
{
int arrynum;
int array1[100];
cout <<"enter the number of elements to be stored in the array: ";
cin >> arrynum;
if (arrynum>100)
{cout <<"Erorr!:the array can't hold more than 100 element"<<endl
<<"the program will stop runing. . . \n";
return 0;}
for (int n=0 ; n<arrynum ; n++)
{
cout <<"Enter the "<<arrynum<<" numbers that you chose:";
cin >> array1[n];
}
return 0;
}
but i still have to write the function void putInOrder (int,int& ); to reorder the number in the array starting from smallest one to largest one
Bazzy, I don't think the guy can just use the sort algorithm provided by STL. In my first programming class I was taught several algorithms and I had to write code for them all.
Did they say what algorithm you should use to sort the array? There are many different ways, and most of them have names; like: Bubble, Insertion, Selection, Shell, Merge, Quick, ...