+ 2
How to create a program in c++ where u input numbers and it will arrange them form ascending and discending order...c++
C++
14 odpowiedzi
+ 4
#include <algorithm>
take input in a array and then use sort(array_name, array_name +n); function, where n is number of inputs.
It is much more efficient then the function you will be defining for sorting, similarily to sort in descending use same sort() function along with a comparator function, you can search more about comparator function.
+ 2
Use sorting algo
+ 1
Have you tried to write program?
+ 1
https://code.sololearn.com/cr2owAeWvUb0/?ref=app
You can try this code.
+ 1
You can use sorting algorithm
0
Try sorting algorithms, I've been working on those lately.
0
Sorry guys what codes to use in ascending and discending do u use arrays???
0
Rhojun Sapon Yes.
0
Do u use the for loop??
0
Rhojun Sapon Yes, you need to iterate through the array inorder to access the items.
0
Ahh okay tnx...
0
Rhojun Sapon I'd recommend using Bubble Sort algorithm, check out my code.
0
Reseve them as an array then sort the array with function sort for example if you want to sort 5 numbers you will reserve them in array arr and sort them with function sort(arr,arr+5);from smallest to largest
Or sort(arr+5,arr); from largest to smallest
but you should calling the library #include
<algorithm> in the program
0
this program is done through sorting algorithms...