+ 2

How to create a program in c++ where u input numbers and it will arrange them form ascending and discending order...c++

C++

2nd Mar 2020, 2:03 PM
Rhojun Sapon
Rhojun Sapon - avatar
14 Respostas
+ 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.
2nd Mar 2020, 4:07 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 2
Use sorting algo
3rd Mar 2020, 7:01 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Have you tried to write program?
2nd Mar 2020, 2:13 PM
Sujan Kharal
Sujan Kharal - avatar
4th Mar 2020, 4:02 AM
Sanchay Kumar
Sanchay Kumar - avatar
+ 1
You can use sorting algorithm
4th Mar 2020, 8:36 AM
🌾 Elina RL Shah 🌾
🌾 Elina RL Shah 🌾 - avatar
0
Try sorting algorithms, I've been working on those lately.
2nd Mar 2020, 2:15 PM
かんでん
かんでん - avatar
0
Sorry guys what codes to use in ascending and discending do u use arrays???
2nd Mar 2020, 2:16 PM
Rhojun Sapon
Rhojun Sapon - avatar
2nd Mar 2020, 2:17 PM
かんでん
かんでん - avatar
0
Do u use the for loop??
2nd Mar 2020, 2:18 PM
Rhojun Sapon
Rhojun Sapon - avatar
0
Rhojun Sapon Yes, you need to iterate through the array inorder to access the items.
2nd Mar 2020, 2:19 PM
かんでん
かんでん - avatar
0
Ahh okay tnx...
2nd Mar 2020, 2:21 PM
Rhojun Sapon
Rhojun Sapon - avatar
0
Rhojun Sapon I'd recommend using Bubble Sort algorithm, check out my code.
2nd Mar 2020, 2:22 PM
かんでん
かんでん - avatar
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
3rd Mar 2020, 12:40 PM
Youssef El--sayed
Youssef El--sayed - avatar
0
this program is done through sorting algorithms...
4th Mar 2020, 9:56 AM
Vaja Dushyant
Vaja Dushyant - avatar