Thank you for this, was trying to wrap my head around this sorting lol I need to dip my head in ice
@PortfolioCourses2 жыл бұрын
You're welcome Olamide! :-D
@raziahmad8779 Жыл бұрын
Excellent explanation sirrr
@PortfolioCourses Жыл бұрын
I’m glad you enjoyed the explanation Razi! :-)
@youssefahmed-io1ko4 ай бұрын
Thank you sir 🙏❤️
@karthik336792 жыл бұрын
Very nice explanation sir🙏
@PortfolioCourses2 жыл бұрын
Thank you! :-)
@trevormotsi85612 жыл бұрын
Thank you very much ... So what if i want descending order only sorting 3 numbers again
@PortfolioCourses2 жыл бұрын
Great question Trevor! 🙂 The numbers are printed out in descending order at the end of the program right now. So you could just do it that way... by sorting them 'ascending' we've also figured out their order in 'descending' order too... it's just that we swap highest and lowest. You could also go through the code and change all the = in the conditions, that would sort 3 numbers in descending order (but you would want to swap the variable names of 'lowest' to 'highest' too in order to make the code make sense).
@trevormotsi85612 жыл бұрын
I've been trying to re-do the same program there that u just did the same way but im having an error on the first *else* I don't know if im making a mistake myself or there's something wrong
@PortfolioCourses2 жыл бұрын
@@trevormotsi8561 The code is available here, it will work: github.com/portfoliocourses/c-example-code/blob/main/sort_three_numbers.c
@antondejoya28873 жыл бұрын
What if there are 4 integers can you do it pls
@PortfolioCourses3 жыл бұрын
The program would start to become very, very large if we keep doing it this way. Even with only 4 numbers, if we were to keep using this approach, we would need another "outer if-statement" that would then contain the code to sort the remaining 3 integers in each branch (about the same size as the code in this example, but repeated 4x). Because the problem becomes too big to solve effectively this way, at this point we would use an array of data and what's called a sorting algorithm to sort the data. One sorting algorithm that people often learned first is called bubble sort, I've made a video on that one: kzbin.info/www/bejne/j6Ldf5qXe7Z4npo As well as on selection sort, which is a different way of sorting numbers in an array: kzbin.info/www/bejne/j5bTe2qcedKsoKs
@prathamreigns20959 ай бұрын
// Online C compiler to run C program online #include int sor(int arr[],int n){ int temp,i,j; for(int i=0;i
@b_jamorolluismiguelr3781 Жыл бұрын
How about negative numbers?
@PortfolioCourses Жыл бұрын
This code should work with negative numbers too. :-)
@tanjinai82112 жыл бұрын
Wow this is a great explanation! Thank you!
@PortfolioCourses2 жыл бұрын
You’re welcome! :-)
@Atrainn2342 жыл бұрын
How can someone write this in pseudocode please?
@PortfolioCourses2 жыл бұрын
Pseudocode has no official rules, it's generally speaking a lot like regular code but with less focus on following specific syntax and more flexibility to write whatever makes sense: en.wikipedia.org/wiki/Pseudocode#Syntax. So a pseudocode version of this would be very, very similar to this code, but the syntax would not need to be nearly as precise... brackets, semicolons, even types, etc, could all be left out.
@Atrainn2342 жыл бұрын
@@PortfolioCourses thanks
@PortfolioCourses2 жыл бұрын
@@Atrainn234 You're welcome! 😀
@nideareyanne53402 жыл бұрын
how can I sort 5 numbers?
@PortfolioCourses2 жыл бұрын
Great question Nidea! :-) If you have 5 numbers, you might want to use something like Insertion Sort: kzbin.info/www/bejne/iquap3Wlmb-kpZo. Or Selection Sort: kzbin.info/www/bejne/j5bTe2qcedKsoKs. You could technically implement something like in this video, but you would have more and more nested if-statements with more and more branches and it would start to get pretty complicated, so I would suggest using a sorting algorithm instead.
@nideareyanne53402 жыл бұрын
@@PortfolioCourses I am looking for a video that is not using an Array while sorting 5 numbers.
@PortfolioCourses2 жыл бұрын
@@nideareyanne5340 That is a difficult question, I don't really know of any easy way to do it or any videos that can help. 😞 The answers I've seen online aren't very easy or 'elegant', like this one: stackoverflow.com/a/64016787. Or this one: stackoverflow.com/a/25070688.