#check wheather a number is divisible by 11 or not without divide it by 11
echo "enter a number:"
read input
temp=$input
#extract digits from the number
i=0
while [ $input -ne 0 ];do
buff=`expr $input % 10`
A[$i]=$buff
i=`expr $i + 1`
input=`expr $input / 10`
done
#.................................
# even and odd sum
odd_sum=0
even_sum=0
for ((j=0;j<i;j++));do
if [ `expr $j % 2` -eq 0 ];then
odd_sum=`expr $odd_sum + ${A[$j]}`
else
even_sum=`expr $even_sum + ${A[$j]}`
fi
done
# display result
if [ $odd_sum -eq $even_sum ];then
echo "$temp is divisible by 11"
else
echo "$temp is not divisible by 11"
fi
# script to find prime factors
echo "enter an integer:"
read input
if [ $input -lt 1 ];then
echo "not allowed!"
exit 1
fi
# find factors and prime
i=2
count=0
flag=0
for ((i;i<$input;));do
if [ `expr $input % $i` -eq 0 ];then
factor=$i
for ((j=2;j<=`expr $factor / 2`;));do
flag=0
if [ `expr $factor % $j` -eq 0 ];then
flag=1
break
fi
j=`expr $j + 1`
done
if [ $flag -eq 0 ];then
echo "[ $factor ]"
count=1
fi
fi
i=`expr $i + 1`
done
if [ $count -eq 0 ];then
echo "no prime factors found except 1 and $input"
fi