Instructions Difficile
Calculatrice avec fonctions
Fonctions · 🚀 Projet
Crée un programme avec 4 fonctions :
int additionner(int a, int b): renvoiea + bint soustraire(int a, int b): renvoiea - bint multiplier(int a, int b): renvoiea * bint diviser(int a, int b): renvoiea / b
Test dans main() :
printf("10 + 3 = %d\n", additionner(10, 3)); // 13
printf("10 - 3 = %d\n", soustraire(10, 3)); // 7
printf("10 * 3 = %d\n", multiplier(10, 3)); // 30
printf("10 / 3 = %d\n", diviser(10, 3)); // 3
Bonus 1 : Modifie diviser() pour afficher un message d'erreur si b vaut 0 (division impossible !). Utilise un if pour tester ce cas.
Bonus 2 : Ajoute une fonction int calculer(int a, char op, int b) qui choisit l'opération selon le caractère op ('+', '-', '*', '/').
Indice : utilise if (op == '+') puis else if (op == '-'), etc., pour choisir l'opération.
ÉDITEUR GCC 14.2 -Wall -Wextra -std=c17
Snippets :
SORTIE
Appuie sur Ctrl+Entrée pour compiler et exécuter.