Find absolute value without conditional

4.81K 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
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.

Categories