Prêt
Instructions Moyen

Valeur absolue

Fonctions · Exercice 5

Écris une fonction int absolu(int n) qui renvoie la valeur absolue d'un nombre (toujours positif).

Test :

printf("%d\n", absolu(5));   // 5
printf("%d\n", absolu(-5));  // 5
printf("%d\n", absolu(0));   // 0

Indice : utilise un if pour tester si n est négatif.

ÉDITEUR
SORTIE
Appuie sur Ctrl+Entrée pour compiler et exécuter.