BashScript Aritmatika

| Saturday, 14 May 2011
Contoh BashScript Aritmatika :

  1. Penjumlahan

#!/bin/bash

echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b

let “ hasil = $a+$b “
echo “ hasil = $hasil “

Setelah file dieksekusi maka hasilnya

Masukkan angka = 2
Masukkan angka = 3
hasil = 5


  1. Pengurangan

#!/bin/bash

echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b

let “ hasil = $a-$b “
echo “ hasil = $hasil “


Setelah file dieksekusi maka hasilnya

Masukkan angka = 5
Masukkan angka = 3
hasil = 2


  1. Perkalian

#!/bin/bash

echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b

let “ hasil = $a*b “
echo “ hasil = $hasil “

Setelah file dieksekusi maka hasilnya

Masukkan angka = 3
Masukkan angka = 5
hasil = 15


  1. Pembagian

#!/bin/bash

echo –n “Masukkan angka = “
read a
echo –n “Masukkan angka = “
read b

let “ hasil = $a/$b “
echo “ hasil = $hasil “

Setelah file dieksekusi maka hasilnya

Masukkan angka = 20
Masukkan angka = 5
hasil = 4

0 comments:

Next Prev
▲Top▲