Find absolute value without conditional

1.30K viewsProgrammingabs C programming
0

How can I find absolute value of a number without using if statement ?

Answered question
0

#include <stdio.h>
#define BYTE_SIZE 8
int main()
{
           int x = -32432;
           printf(“Absolute valur of %d is %d “, x, (x + (x >> sizeof(x)*BYTE_SIZE – 1)) ^ (x >> sizeof(x)*BYTE_SIZE – 1));
           return 0;
}

Answered question

Categories