Skip to content
Home » Program to return Absolute value in C

Program to return Absolute value in C

Learn about Program to return Absolute value in C in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Program to return Absolute value in C

Absolute value describes the distance of a number on the number line from 0 without taking direction into account. A number’s absolute value is always positive (distance can never be negative). In this section, we will create a program to find the absolute value in C.

Program:

#include<stdio.h>
#include<stdlib.h>
int main()
{
  int n;

  printf("Enter a number: ");
  scanf("%d",&n);

  n=abs(n);
  printf("Absolute value = %d\n", n);

  return 0;
}

Output:

Enter a number: -4
Absolute value = 4

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C program to find the largest of three numbers using if statements
C Program to Find Largest of Three Numbers Using AND (&&) operator