![]() |
|
[C] C++ entering numbers and displaying - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] C++ entering numbers and displaying (/showthread.php?tid=6116122) |
C++ entering numbers and displaying - dawid17 - Oct 17, 2020 So I got this code, I input three numbers. Now I want to display them in a for loop. From smallest to biggest, and in another loop from biggest to smallest. How can I do this? Code int main() {I have done this like this but I think it's not a proper way to do it? Code for(int i=0; i<=0; i++) {RE: C++ entering numbers and displaying - saltycracker - Oct 17, 2020 Well you'll have to decide how you want to sort these integers. You can use a old fashion array or a C++ container or even recursion. Its really up to you. The easiest is qsort and arrays. https://www.tutorialspoint.com/c_standard_library/c_function_qsort.htm A not so easy way is to create an array of integer pointers to the integers and sort the pointers(smallest to largest or largest to smallest). Here's a solution which uses an array of pointers to the integers... Code #include <iostream>How about one that uses a C++ set? Code #include <iostream> |