Oct 22, 2015 at 4:14am UTC
#include <stdio.h>
void swap(int *a, int *b, int *c)
{
int max,min,mid;
max = *a>*b ? *a:*b;
max = max>*c ? max:*c;
min = *a<*b ? *a:*b;
min = min<*c ? min:*c;
mid = *a + *b + *c - max - min;
*c = max;
*b = mid;
*a = min;
}
int main()
{
int a,b,c;
a=20;
b=23;
c=10;
printf("a = %d, b = %d, c = %d\n", a , b, c);
swap(&a,&b,&c);
printf("a = %d, b = %d, c = %d\n", a , b, c);
return 0;
}
In the code what does the "?" mean?
max = *a>*b ? *a:*b;
max = max>*c ? max:*c;
min = *a<*b ? *a:*b;
min = min<*c ? min:*c;
Oct 22, 2015 at 6:03am UTC
so if you were going to write the part of
void swap(int *a, int *b, int *c)
{
int max,min,mid;
max = *a>*b ? *a:*b;
max = max>*c ? max:*c;
min = *a<*b ? *a:*b;
min = min<*c ? min:*c;
mid = *a + *b + *c - max - min;
*c = max;
*b = mid;
*a = min;
}
into an if and else statement how would you do that?
Oct 22, 2015 at 6:25am UTC
Hi,
Have a look in the tutorial, it shows examples.
Edit:
No, never mind - the question is probably answered in your other duplicate post
Please don't do this, it is annoying for those who spend their time to reply, that time is effectively wasted.
I am also less than enthused about your lack of willingness to use code tags.
Last edited on Oct 22, 2015 at 6:29am UTC