Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. float soma(float a, float b)
  4. {
  5.     float soma;
  6.     soma = a + b;
  7.     return soma;
  8. }
  9.  
  10. float subtrai(float a, float b)
  11. {
  12.     float subtracao;
  13.     subtracao = a - b;
  14.     return subtracao;
  15. }
  16.  
  17. float multiplica (float a, float b)
  18. {
  19.     float mult;
  20.     mult = a * b;
  21.     return mult;
  22. }
  23.  
  24. float divide(float a, float b)
  25. {
  26.     float div;
  27.     if(b == 0)
  28.     {
  29.         printf("Impossivel dividir com denominador igual a 0\n");
  30.         return 0;
  31.     }
  32.     else
  33.     {
  34.         div = a / b;
  35.         return div;
  36.     }
  37. }
  38.  
  39. int main(void)
  40. {
  41.    
  42.     float n1, n2;
  43.     char sinal;
  44.     printf("Digite a operacao: (num1 operacao num2): ");
  45.     scanf("%f %c %f", &n1, &sinal, &n2);
  46.  
  47.     if(sinal == '+')
  48.     {
  49.         printf("%f %c %f = %f\n", n1, sinal, n2, soma(n1, n2));
  50.     }
  51.     else if(op == '-')
  52.     {
  53.         printf("%f %c %f = %f\n", n1, sinal, n2, subtrai(n1, n2));
  54.     }
  55.     else if(op == 'x')
  56.     {
  57.         printf("%f %c %f = %f\n", n1, sinal, n2, multiplica(n1, n2));
  58.     }
  59.     else if(op == '/')
  60.     {
  61.         printf("%f %c %f = %f\n", n1, sinal, n2, divide(n1, n2));
  62.     }
  63.    
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement