Advertisement
LightProgrammer000

Calculos Matematicos

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