Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- function inputMat(){
- echo "Enter Matrix A: "
- read -a a
- echo "Enter Matrix B: "
- read -a b
- }
- function displayMat(){
- for(( i=0; i<4; i++ ))
- do
- if(( i==2 )) # new line for next row
- then echo ""
- fi
- echo -n "${c[i]} "
- done
- }
- function add(){
- for(( i=0; i<4; i++ ))
- do
- let c[$i]=${a[$i]}+${b[$i]}
- done
- }
- function sub(){
- for(( i=0; i<4; i++ ))
- do
- let c[$i]=${a[$i]}-${b[$i]}
- done
- }
- function mul(){
- let c[0]=${a[0]}*${b[0]}+${a[1]}*${b[2]}
- let c[1]=${a[0]}*${b[1]}+${a[1]}*${b[3]}
- let c[2]=${a[2]}*${b[0]}+${a[3]}*${b[2]}
- let c[3]=${a[2]}*${b[1]}+${a[3]}*${b[3]}
- }
- inputMat
- echo -n "1.Add 2. Subtract 3. Multiply: "
- read ip
- case $ip in
- 1):
- add;;
- 2):
- sub;;
- 3):
- mul;;
- esac
- displayMat
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement