Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Matrix addition, subtraction and multiplication
#!/bin/bash # GNU bash, version 4.4.20 n=2 x=(1 2 3 4) y=(5 6 7 8) z=(0 0 0 0) read ch case $ch in 1) for((i=0;i<n;i++)) do for((j=0;j<n;j++)) do z[$(($n*$i+$j))]=$(( ${x[$(($n*$i+$j))]} + ${y[$(($n*$i+$j))]} )) done done echo "The new matrix after addition is" echo ${z[*]} ;; 2) for((i=0;i<n;i++)) do for((j=0;j<n;j++)) do z[$(($n*$i+$j))]=$(( ${y[$(($n*$i+$j))]} - ${x[$(($n*$i+$j))]} )) done done echo "The new matrix after subtraction is" echo ${z[*]} ;; 3) for((i=0;i<n;i++)) do for((j=0;j<n;j++)) do prod[$(($n*$i+$j))]=0 for((k=0;k<n;k++)) do prod[$(( $n*$i+$j ))]=$(( ${prod[$(( $n*$i+$j ))]} + $(( ${x[$(( $n*$i+$k ))]} * ${y[$(( $n*$k+$j ))]} )) )) done done done echo "The new matrix after multiplication is" echo ${prod[*]} ;; *) echo " exit to quit" ;; esac
run
|
edit
|
history
|
help
0
asdf
dosent work yet-
gsup awk
Just go away Dolls.EXE
a shell script to say good morning/afternoon/evening
learning bash 101
Test1
prog1
multi
hadikhan