Implementing the conditional operator ?: with the function int cond(int x, int y, int z) (should not use if/else/while)

Jaks_maths 0 Tallied Votes 216 Views Share

One line stament which acts as a conditional operator ?:
If x=true, returns y else returns z.

#include<stdio.h>
int cond(int x,int y,int z)
{
return (((~(~x+1))&~y&z)|((~x+1)&(y&~z))|(y&z));
}

main()
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
printf("%d",cond(x,y,z));
}