Sunday, 17 June 2012

Write a shell script to add two arrays


clear
echo enter the size of array..
read s
echo enter the elements of array A...
for ((i=0; $i<$s; i++))
do
            read a[$i]
done
echo enter the elements of Array B
for ((i=0; $i<$s; i++))
do
            read b[$i]
done
echo The sum of array is...
for ((i=0; $i<$s; i++))
do
            c[$i]=`expr ${a[$i]} + ${b[$i]}`
            echo ${c[$i]}
done

No comments:

Post a Comment