tanky321
Member level 1
Im trying to right a program that is given 5 integers, it then sorts the integers in numerical order. Catch is it has to use if else statements or loops.
Its for a class im in, and im at a complete loss. Heres what I have so far, only for the first two numbers, but it doesnt work. Any tips or help would be appreciated.
void order(int a, int b, int c, int d, int e)
{ int num_1=0;
int num_2=0;
if(a<b && a<c && a<d && a<e)
{num_1=a;
a=0;}
else if(b<a && b<c && b<d && b<e)
{num_1=b;
b=0;}
else if(c<a && c<b && c<d && c<e)
{num_1=c;
c=0;}
else if(d<a && d<b && d<c && d<e)
{num_1=d;
d=0;}
else
{num_1=e;
e=0;}
if (a<b && a<c && a<d && a<e && a!=num_1 && a!=0)
{num_2=a;
a=0;}
else if(b<a && b<c && b<d && b<e && b!=num_1 && b!=0)
{num_2=b;
b=0;}
else if(c<a && c<b && c<d && c<e && c!=num_1 && c!=0)
{num_2=c;
c=0;}
else if(d<a && d<b && d<c && d<e && d!=num_1 && d!=0)
{num_2=d;
d=0;}
else if(e<a && e<b && e<c && e<d && e!=num_1 && e!=0)
{num_2=e;
e=0;}
printf("%d %d %d\n\n\n", num_1,num_2);
}
Its for a class im in, and im at a complete loss. Heres what I have so far, only for the first two numbers, but it doesnt work. Any tips or help would be appreciated.
void order(int a, int b, int c, int d, int e)
{ int num_1=0;
int num_2=0;
if(a<b && a<c && a<d && a<e)
{num_1=a;
a=0;}
else if(b<a && b<c && b<d && b<e)
{num_1=b;
b=0;}
else if(c<a && c<b && c<d && c<e)
{num_1=c;
c=0;}
else if(d<a && d<b && d<c && d<e)
{num_1=d;
d=0;}
else
{num_1=e;
e=0;}
if (a<b && a<c && a<d && a<e && a!=num_1 && a!=0)
{num_2=a;
a=0;}
else if(b<a && b<c && b<d && b<e && b!=num_1 && b!=0)
{num_2=b;
b=0;}
else if(c<a && c<b && c<d && c<e && c!=num_1 && c!=0)
{num_2=c;
c=0;}
else if(d<a && d<b && d<c && d<e && d!=num_1 && d!=0)
{num_2=d;
d=0;}
else if(e<a && e<b && e<c && e<d && e!=num_1 && e!=0)
{num_2=e;
e=0;}
printf("%d %d %d\n\n\n", num_1,num_2);
}