Absolute value P96275


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py   main.hs

html

Write a function that returns the absolute value of an integer n.

Interface

C++
int absolute(int n);
C
int absolute(int n);
Java
public static int absolute(int n);
Haskell
absolute :: Int -> Int
Python
absolute(n) # returns int
 
absolute(n: int) -> int

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    absolute(42) → 42
  • Input/Output

    absolute(-23) → 23
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Haskell Java Python
    User solutions
    Brainfuck C C++ Haskell Java Python