In: Computer Science
I'm trying to write a program that reads 3 heights of kids and puts them in ascending order using if and else statements but i'm having trouble
#include<stdio.h>
int main()
{
int k1,k2,k3;
printf("Enter height of kid #1 >");
scanf("%d",&k1);
printf("Enter height of kid #2 >");
scanf("%d",&k2);
printf("Enter height of kid #3 >");
scanf("%d",&k3);
if(k3>k2>k1)
{
printf("In ascending order %d %d %d",k3,k2,k1);
}
else if(k3>k1>k2)
{
printf("In ascending order %d %d %d",k3,k1,k2);
}
else if(k2>k3>k1)
{
printf("In ascending order %d %d %d",k2,k3,k1);
}
else if(k2>k1>k3)
{
printf("In ascending order %d %d %d",k2,k1,k3);
}
else if(k1>k3>k2)
{
printf("In ascending order %d %d %d",k1,k3,k2);
}
else if(k1>k2>k3)
{
printf("In ascending order %d %d %d",k1,k2,k3);
}
}
#include<stdio.h> int main() { int k1, k2, k3; printf("Enter height of kid #1 >"); scanf("%d", &k1); printf("Enter height of kid #2 >"); scanf("%d", &k2); printf("Enter height of kid #3 >"); scanf("%d", &k3); if (k3 <= k2 && k2 <= k1) { printf("In ascending order %d %d %d", k3, k2, k1); } else if (k3 <= k1 && k1 <= k2) { printf("In ascending order %d %d %d", k3, k1, k2); } else if (k2 <= k3 && k3 <= k1) { printf("In ascending order %d %d %d", k2, k3, k1); } else if (k2 <= k1 && k1 <= k3) { printf("In ascending order %d %d %d", k2, k1, k3); } else if (k1 <= k3 && k3 <= k2) { printf("In ascending order %d %d %d", k1, k3, k2); } else if (k1 <= k2 && k2 <= k3) { printf("In ascending order %d %d %d", k1, k2, k3); } return 0; }