array calculator store in 3rd Array



 shell script to enter numbers in 2 (1 dimension) arrays. Store it in 3rd array. Ask the user for: 2 arrays additions 2 arrays subtraction 2 arrays multiplication

clear

read -p "Enter array Size :" size

echo "Array 1"
for((i=0;i<size;i++))
do
    read arr1[$i]
done

echo "Array 2"
for((i=0;i<size;i++))
do
    read arr2[$i]
done

echo "Array1 :" ${arr1[*]}
echo "Array2 :" ${arr2[*]}
while((1))
do
    echo "Enter Your Choice"
    echo "1 for Addition"
    echo "2 for Subtraction"
    echo "3 for Multipication"
    echo "4 for Exit"
    echo
    read -p "Enter Your Choice :" ch

    for((i=0;i<size;i++))
    do
        if((ch==1));then
            arr3[$i]=$((${arr1[$i]}+${arr2[$i]}))
        elif((ch==2));then
            arr3[$i]=$((${arr1[$i]}-${arr2[$i]}))
        elif((ch==3));then
            arr3[$i]=$((${arr1[$i]}+${arr2[$i]}))
        elif((ch==4));then
            exit 1
        else
            echo "Invalid Choice"
            break
        fi
    done

    if((ch==1));then
        echo "Addtion is :" ${arr3[*]}
    elif((ch==2));then
        echo "Subtraction is :" ${arr3[*]}
    elif((ch==3));then
        echo "Multipication is :" ${arr3[*]}
    fi
done
array calculator store in 3rd Array array calculator store in 3rd Array Reviewed by Unknown on 6:27 pm Rating: 5

No comments: