-1

Write a program arr_calc to perform array addition and array multiplication, The program takes 4 arguments:

Argument 1: The file name of the input array A
Argument 2: The file name of the input array B
Argument 3: The file name of the output array C
Argument 4: The calculation (a for addition, m for multiplication)

e.g., arr_calc file1 file2 file3 a

closed as unclear what you're asking by jasonwryan, slm, Ramesh, iruvar, Gilles Jun 1 '14 at 22:49

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What are you trying to do exactly? There is no such thing as multiplication of arrays (or if you prefer, there are many different concepts that could be called multiplication of arrays, so you need to say which one you mean). If don't manage to give a precise description, at least give an example! If you want to do matrix operations, the shell is not a good language. – Gilles Jun 1 '14 at 22:49
3

using shell Programming:
This is a shell script to adding matrices with each other:

#!/bin/bash 

read -p "Enter the matrix order [mxn] : " t 
m=${t:0:1} 
n=${t:2:1} 

echo "Enter the elements for first matrix" 
for i in `seq 0 $(($m-1))` 
do 
for j in `seq 0 $(($n-1))` 
 do 
     read x[$(($n*$i+$j))] 
done 
done 

echo "Enter the elements for second matrix" 
for i in `seq 0 $(($m-1))` 
do 
for j in `seq 0 $(($n-1))` 
do 
    read y[$(($n*$i+$j))] 
    z[$(($n*$i+$j))]=$((${x[$(($n*$i+$j))]}+${y[$(($n*$i+$j))]})) 
done 
done 

echo "Matrix after addition is"  
for i in `seq 0 $(($m-1))` 
do 
for j in `seq 0 $(($n-1))` 
do 
    echo -ne "${z[$(($n*$i+$j))]}\t" 
done 
echo -e "\n" 
done 

exit 0 

for matrices Multiplication, you can use the same logic above.

Not the answer you're looking for? Browse other questions tagged or ask your own question.