Jake - 1 year ago 70

C Question

I just wonder how to find median of two numbers without using division.

do not use this conditions :

- int median = (a + b) >> 1;
- four fundamental arithmetic operations

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

I think this may be helpful -->

```
int a,b,i,j;
if (a>b)
{
int temp = a;
a = b;
b = temp;
}
for(i=a,j=b;i<j;i++,j--)
continue;
if(i==j)printf("%d\n", i);
else printf("%lf\n", (double)(i)-0.5);
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**