Advertisement
LightProgrammer000

Cálculos Matemáticos [Operações Básicas]

Nov 22nd, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | None | 0 0
  1. # !/bin/bash
  2. # Assunto: Calculos Matematicos
  3. # Compilar: chmod 777
  4.  
  5. ## Script ##
  6. echo ""
  7.  
  8. # Funcao
  9. soma()
  10. {
  11.     soma=`echo "scale=2; ($n1 + $n2)" | bc `
  12.     echo "- Soma: $soma"
  13. }
  14.  
  15. subtracao()
  16. {
  17.     sub=`echo "scale=2; ($n1 - $n2)" | bc`
  18.     echo "- Subtracao: $sub"
  19. }
  20.  
  21. multiplicacao()
  22. {
  23.     mult=`echo "scale=2; ($n1 * $n2)" | bc`
  24.     echo "- Multiplicacao: $mult"
  25. }
  26.  
  27. divisao()
  28. {
  29.     div=`echo "scale=2; ($n1 / $n2)" | bc`
  30.     echo "- Divisao: $div"
  31. }
  32.  
  33. potenciacao()
  34. {
  35.     pot=`echo "scale=2; ($n1 ^ $n2) " | bc`
  36.     echo "- Potenciacao: $pot"
  37. }
  38.  
  39. raizQuadrada()
  40. {
  41.     rq1=`echo "scale=2; sqrt( $n1 )" | bc`
  42.     rq2=`echo "scale=2; sqrt( $n2 )" | bc`
  43.     echo "- Raiz Quadrada(N1): $rq1"
  44.     echo "- Raiz Quadrada(N2): $rq2"
  45. }
  46.  
  47. # Programa
  48. echo ""
  49. echo "---------- CALCULADORA ----------"
  50.  
  51. # Entrada de dados
  52. read -p "Digite N1: " n1
  53. read -p "Digite N2: " n2
  54.  
  55. # Saida de dados & chamada de funcao
  56. echo ""
  57. echo "------- RESULTADO ----------"
  58. soma
  59. subtracao
  60. multiplicacao
  61. potenciacao
  62. raizQuadrada
  63. echo "----------------------------"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement