Sort Three Numbers | C Programming Example

  Рет қаралды 20,540

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 30
@olamidecooldude
@olamidecooldude 2 жыл бұрын
Thank you for this, was trying to wrap my head around this sorting lol I need to dip my head in ice
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome Olamide! :-D
@raziahmad8779
@raziahmad8779 Жыл бұрын
Excellent explanation sirrr
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I’m glad you enjoyed the explanation Razi! :-)
@youssefahmed-io1ko
@youssefahmed-io1ko 4 ай бұрын
Thank you sir 🙏❤️
@karthik33679
@karthik33679 2 жыл бұрын
Very nice explanation sir🙏
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you! :-)
@trevormotsi8561
@trevormotsi8561 2 жыл бұрын
Thank you very much ... So what if i want descending order only sorting 3 numbers again
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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).
@trevormotsi8561
@trevormotsi8561 2 жыл бұрын
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
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@trevormotsi8561 The code is available here, it will work: github.com/portfoliocourses/c-example-code/blob/main/sort_three_numbers.c
@antondejoya2887
@antondejoya2887 3 жыл бұрын
What if there are 4 integers can you do it pls
@PortfolioCourses
@PortfolioCourses 3 жыл бұрын
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
@prathamreigns2095
@prathamreigns2095 9 ай бұрын
// 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
@b_jamorolluismiguelr3781 Жыл бұрын
How about negative numbers?
@PortfolioCourses
@PortfolioCourses Жыл бұрын
This code should work with negative numbers too. :-)
@tanjinai8211
@tanjinai8211 2 жыл бұрын
Wow this is a great explanation! Thank you!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome! :-)
@Atrainn234
@Atrainn234 2 жыл бұрын
How can someone write this in pseudocode please?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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.
@Atrainn234
@Atrainn234 2 жыл бұрын
@@PortfolioCourses thanks
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@Atrainn234 You're welcome! 😀
@nideareyanne5340
@nideareyanne5340 2 жыл бұрын
how can I sort 5 numbers?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
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.
@nideareyanne5340
@nideareyanne5340 2 жыл бұрын
@@PortfolioCourses I am looking for a video that is not using an Array while sorting 5 numbers.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@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.
@morisra12
@morisra12 Жыл бұрын
thank you! :)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@tanjinai8211
@tanjinai8211 2 жыл бұрын
Wow this is a great explanation! Thank you!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You're welcome! 😀
you will never ask about pointers again after watching this video
8:03
Selection Sort | C Programming Example
8:00
Portfolio Courses
Рет қаралды 64 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Quando A Diferença De Altura É Muito Grande 😲😂
00:12
Mari Maria
Рет қаралды 45 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
C sort an array 💱
6:02
Bro Code
Рет қаралды 103 М.
Bubble Sort | C Programming Example
14:53
Portfolio Courses
Рет қаралды 136 М.
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 905 М.
My 2 Year Journey of Learning C, in 9 minutes
8:42
VoxelRifts
Рет қаралды 674 М.
the TRUTH about C++ (is it worth your time?)
3:17
Low Level
Рет қаралды 807 М.
Using qsort() To Sort An Array | C Programming Example
9:46
Portfolio Courses
Рет қаралды 29 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 846 М.
The evil clown plays a prank on the angel
00:39
超人夫妇
Рет қаралды 53 МЛН