43 lines
966 B
C
43 lines
966 B
C
|
/* Calculatrice */
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
int main() {
|
||
|
int a, b;
|
||
|
char operateur;
|
||
|
div_t result_div;
|
||
|
|
||
|
printf("Indiquez l'opération mathématique à résoudre, sans espace.\n");
|
||
|
printf(" - opérateurs possibles [+, -, *, /]\n");
|
||
|
printf("> ");
|
||
|
scanf("%d%c%d", &a, &operateur, &b);
|
||
|
|
||
|
switch (operateur) {
|
||
|
case '+':
|
||
|
printf("%d\n", a + b);
|
||
|
break;
|
||
|
case '-':
|
||
|
printf("%d\n", a - b);
|
||
|
break;
|
||
|
case '*':
|
||
|
printf("%d\n", a * b);
|
||
|
break;
|
||
|
case '/':
|
||
|
if (b == 0) {
|
||
|
printf("Vous ne pouvez pas diviser par 0 !\n");
|
||
|
return 1;
|
||
|
}
|
||
|
result_div = div(a, b);
|
||
|
printf("%d + %d\n", result_div.quot, result_div.rem);
|
||
|
break;
|
||
|
default:
|
||
|
printf("Je n'ai pas compris...\n");
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
|
||
|
return 0;
|
||
|
}
|