Write a program that will sort three numbers. The user will enter three numbers int variables named num1, num2 and num3. You will pass by reference these three values to a function called sortNums(), which will then put them order from smallest to largest. Num1 will hold the smallest value, num2 will hold the middle value and num3 will hold the largest value. Print the numbers in order from main().
how can i fix my if statement. when i put 123 it comes out right and when i put 321 it comes out right but when i put 213 it comes out wrong.
//function prototype
void sortNums(int*,int*,int*);
int main()
{
//Variables
int num1;
int num2;
int num3;
//refernce numbers variables
int *one;
int *two;
int *three;
//inputing nums
printf("Please enter num1: \n");
scanf("%d", &num1);
printf("Please enter num2: \n");
scanf("%d", &num2);
printf("Please enter num3: \n");
scanf("%d",&num3);
//putting reference numbers into variables
one = &num1;
two = &num2;
three = &num3;
sortNums(one,two,three);
printf("num1 %d\n",num1);
printf("num2 %d\n",num2);
printf("num3 %d\n",num3);
getch();
return 0;
}
//function
void sortNums(int *one,int *two, int *three)
{
int n1 = *one;
int n2 = *two;
int n3 = *three;
if ((n1 > n2) && (n2 > n3)){
*one = n3;
*two = n2;
*three = n1;
}
else if ((n1 > n2) &&(n2 < n3) ){
*one = n2;
*two = n3;
*three = n1;
}
else {
*one = n1;
*two = n2;
*three = n3;
}
}