Program To Print The Absolute Value In C

C program to print the absolute value of the given number.

Absolute value is the actual value or magnitude without any sign. Suppose user entered a value -12 then the output will be 12. For this program you have to include a new header file “math.h” and you can use the abs() function to display the absolute value.

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int n,result;
clrscr();

printf(“enter any number”);
scanf(“%d”,&n);

result=abs(n); 

printf(“%d”,result);
getch();
}

Output:

absolute value in C

Leave a Reply