mdlib

"Calculadora"

Apr 3rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<locale.h>
  3. #include<ctype.h>
  4.  
  5. int main(){
  6.     setlocale(LC_ALL, "Portuguese");
  7.     int x, y;
  8.     char esc;
  9.    
  10.     printf("Digite X: ");
  11.     scanf("%d", &x);
  12.     setbuf(stdin, NULL);
  13.    
  14.     printf("Digite Y: ");
  15.     scanf("%d", &y);
  16.     setbuf(stdin, NULL);
  17.     do{
  18.     printf("\nEscolha\n\nA - Adição\nS - Subtração\nM - Multiplicação\nD - Divisão\n"); 
  19.     scanf("%c", &esc);
  20.     setbuf(stdin, NULL);
  21.     esc = tolower(esc);
  22.     }while(esc != 'a' && esc != 's' && esc != 'm' && esc != 'd');
  23.  
  24.    
  25.     switch(esc){
  26.         case 'a' : printf("%d + %d = %d", x,y,x+y);
  27.         break;
  28.        
  29.         case 's' : printf("%d - %d = %d",x,y,x-y);
  30.         break;
  31.        
  32.         case 'm' : printf("%d * %d = %d",x,y,x*y);
  33.         break;
  34.        
  35.         case 'd' : if (y==0) printf("Invalido, denominador = 0");else printf("%d / %d = %.2f",x,y,(float)x/y);
  36.         break;
  37.     }
  38. }
Add Comment
Please, Sign In to add comment