Jake Jake - 3 months ago 9
C Question

Write c program to find mean of two numbers without using division

I just wonder how to find

mean
of two numbers without using division.

do not use these conditions :


  • int mean = (a + b) >> 1;

  • four fundamental arithmetic operations


Answer

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);
Comments