C program to find the absolute value of a number; In this tutorial, you will learn how to find absolute value of a number in the c program with help of abs() function and arithmetic operator.
Programs To Find Absolute Value of a Number in C
- C Program To Find Absolute Value of a Number Using abs() function
- C Program To Find Absolute Value of a Number using Arithmetic operator
C Program To Find Absolute Value of a Number Using abs() function
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num;
printf("Enter a positive or negative number :- ");
scanf("%d", &num);
printf("Absolute Value of %d is %d\n", num, abs(num));
return 0;
}
C Program To Find Absolute Value of a Number using Arithmetic operator
#include<stdio.h>
#include<stdlib.h>
int main()
{
int num, aNum;
printf("Enter a positive or negative number :- ");
scanf("%d", &num);
if(num<0){
aNum = (-1)*num;
printf("Absolute Value of %d is %d\n", num, aNum);
}else{
printf("Absolute Value of %d is %d\n", num, num);
}
return 0;
}