DEV Community

Discussion on: Absolute Number in C Language

Collapse
 
pauljlucas profile image
Paul J. Lucas

A much simpler implementation is:

int absolute( int x ) {
   return x < 0 ? -x : x;
}
Enter fullscreen mode Exit fullscreen mode

And C has had a boolean type since C99; see here.

Collapse
 
sukma_wardana profile image
Sukma Wardana

Oh, you're right? That's simpler and easier to understand. Thanks for sharing the solutions and info about boolean type in C. I will add it to my notes :)