Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # !/bin/bash
- # Assunto: Calculos Matematicos
- # Compilar: chmod 777
- ### Funcoes ###
- # Soma
- soma()
- {
- soma=$(echo "scale=2; ($n1 + $n2)" | bc)
- echo " - Soma: $soma"
- }
- # Subtracao
- subtracao()
- {
- sub=$(echo "scale=2; ($n1 - $n2)" | bc)
- echo " - Subtracao: $sub"
- }
- # Multiplicacao
- multiplicacao()
- {
- mult=$(echo "scale=2; ($n1 * $n2)" | bc)
- echo " - Multiplicacao: $mult"
- }
- # Divisao
- divisao()
- {
- div=$(echo "scale=2; ($n1 / $n2)" | bc)
- echo " - Divisao: $div"
- }
- # Potenciacao
- potenciacao()
- {
- pot=$(echo "scale=2; ($n1 ^ $n2) " | bc)
- echo " - Potenciacao: $pot"
- }
- # Raiz Quadrada
- raizQuadrada()
- {
- rq1=$(echo "scale=2; sqrt($n1)" | bc)
- rq2=$(echo "scale=2; sqrt($n2)" | bc)
- echo " - Raiz Quadrada(N1): $rq1"
- echo " - Raiz Quadrada(N2): $rq2"
- }
- ################
- ### PROGRAMA ###
- ################
- clear
- echo ""
- echo " ---------- CALCULADORA ---------- "
- echo ""
- # Entrada de dados
- echo -n " - Digite N1: "
- read n1
- echo -n " - Digite N2: "
- read n2
- # Saida de dados & chamada de funcao
- echo ""
- echo " ------- RESULTADO ---------- "
- soma
- subtracao
- multiplicacao
- potenciacao
- raizQuadrada
- echo " ---------------------------- "
- echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement