Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am confused ....i have write right code for while but its not working. I have tried many ways to use while but no one is working....
Even i have usind chmod ....but it is not working please help me

What I have tried:

echo "enter a number"
read n
j=$n
s=0

while [ $n -gt 0 ]
do
         r='expr $n % 10'
         n='expr $n / 10'
         s='expr $s + $r \* $r \* $r'
done

if test $s -eq $j
then
         echo "Armstrong number"
else
         echo "not an armstrong"
fi
Posted
Updated 17-Oct-16 8:21am
v2
Comments
Mohibur Rashid 11-May-16 11:19am    
There is a difference between ` and '. You are suppose to pick `
Naveen Roy 26-Jan-17 4:14am    
you was right sir why did not you post in solution

I have finally got this to run by removing all the ^M characters at the end of each line in the script file. Note that these characters do not show up when the file is listed, but are quite clearly visible when editing the file with vi. I suspect this is the old Windows vs Unix end of line issue which comes up from time to time.
 
Share this answer
 
I have wrongly typed ` its actully shift + ~ i.e. `
That was the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900