solution 1:-
#!/bin/bash
# Prompt the user to enter the numbers
echo "Enter a list of numbers (space-separated):"
read -a numbers
# Initialize variables
largest=${numbers[0]}
position=0
solution 2:-
# Find the largest number and its position
for ((i=1; i<${#numbers[@]}; i++))
do
if (( ${numbers[i]} > largest ))
then
largest=${numbers[i]}
position=$i
fi
done
# Display the largest number and its position
echo "The largest number is $largest at position $position."
#!/bin/bash
# Prompt the user to enter the numbers
echo "Enter a list of numbers (space-separated):"
read -a numbers
# Initialize variables
largest=-999999
position=-1
# Find the largest number and its position
for i in "${!numbers[@]}"
do
if (( ${numbers[i]} > largest ))
then
largest=${numbers[i]}
position=$i
fi
done
# Display the largest number and its position
echo "The largest number is $largest at position $position."
Post a Comment
If you have any doubts, Please let me know
Thanks!