Advertisement
yanni_yagami

calculer A et B

Dec 6th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.     float A, B;
  5.     char op;
  6.  
  7.     printf("veillez entrer A et B : ");
  8.     scanf("%f %f", &A, &B);
  9.  
  10.     printf("\nveillez selectionner un des operateurs suivants :\n");
  11.     printf("'+' addition\n");
  12.     printf("'-' soustraction\n");
  13.     printf("'*' multiplication\n");
  14.     printf("'/' devision\n\n");
  15.     printf("votre selection : ");
  16.     scanf(" %c", &op);
  17.  
  18.     switch(op) {
  19.         case '+': printf(" %.2f + %.2f = %.2f", A, B, A+B); break;
  20.  
  21.         case '-': printf(" %.2f - %.2f = %.2f", A, B, A-B); break;
  22.  
  23.         case '*': printf(" %.2f * %.2f = %.2f", A, B, A*B); break;
  24.  
  25.         case '/': if(B != 0) {printf(" %.2f / %.2f = %.2f", A, B, A/B); break;} else printf("devision sur 0 est impossible."); break;
  26.  
  27.         default: printf("operateur incorrecte");
  28.     }
  29.  
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement