Home » Unix » shell script » Write a shell script to check whether an inputed number is harshad number or not

Write a shell script to check whether an inputed number is harshad number or not

echo "Enter Any Number::"
read n1

r=0
s=0
temp=$n1

while [ $n1 -ne 0 ]
do
	r=` expr $n1 % 10 `
	s=` expr $r + $s `
	n1=` expr $n1 / 10 `
done

h=` expr $temp % $s `

if [ $h -eq 0 ]
then
	echo "$temp is Harshad Number"
else
	echo "Tata Bye Bye..."
fi

1 Comment

Leave a Reply to Unix shell script from basic to advance – AppXwinD Cancel reply

Your email address will not be published. Required fields are marked *