C program to find absolute value of a number using macros

C program to find absolute value of a number using macros


Output:

Enter a value to get its absolute value: -5

The absolute value is 5

Implementation:


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define absolute(x) if(x<0)\
                    n=-(n);
int main(void) {
 int n;
 printf("Enter a value to get its absolute value:\n");
 scanf("%d",&n);
 absolute(n);
 printf("The absolute value is %d",n);
 return 0;
}