SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to calculate absolute value
C program to calculate absolute value
Output:
Enter a value to get its absolute value:
-5
The absolute value of -5 is 5
Implementation:
#include
#include
#include
int main(void) { int n; printf("Enter a value to get its absolute value:\n"); scanf("%d",&n); printf("\nThe absolute value of %d is %d",n,abs(n)); return 0; }
Other Implementations:
Implementation 1:
#include
#include
#include
int main(void) { int n; printf("Enter a value to get its absolute value:\n"); scanf("%d",&n); if(n<0) { n=-(n); printf("The absolute value of -%d is %d\n",n,n); } else { printf("The absolute value of %d is %d\n",n,n); } return 0; }
PREVIOUS
NEXT
HOME