Skip to content

Instantly share code, notes, and snippets.

@Programentics
Created March 4, 2019 22:19
Sorting using 3 variables in C language
#include<stdio.h>
void main(){
int n1, n2, n3 , temp;
printf("Enter First Number");
scanf("%d", &n1);
printf("Enter Second Number");
scanf("%d", &n2);
printf("Enter Third Number");
scanf("%d", &n3);
if(n1 > n2)
{
temp = n1; // 20 <== 20
n1 = n2; // 30 <== 30
n2 = temp; // 20 <== 20
}
if(n2 > n3)
{
temp = n2;
n2 = n3;
n3 = temp;
}
if(n1 > n3)
{
temp = n1;
n1 = n3;
n3 = temp;
}
printf("The sorted numbers are: %d \n %d \n %d", n1 , n2 , n3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment