Sorting Using 3 Variables in C Language
Learn, how you can sort values using three variables easily. However, there are many methods you can do it from here is the one.
After including the library and creating the main method.
1. First, we'll declared three variables 'n1', 'n2' , 'n3' and temporary variable 'temp'
2. Then, we'll be taking input from users in these three variables, 'n1', 'n2', 'n3'
3. After that we're using the if-else condition to swap variables:
if n1 is greater than n2, then we're swapping the value using the temporary variable
if n2 is greater than n3, then we're swapping the value using the temporary variable
if n1 is greater than n3, then we're swapping the value using the temporary variable
4. After all the swapping we're printing the value after swapping.
Comments
Post a Comment