SourceCodePoint
Wednesday, 18 December 2013
Write a linux shell program to perform find the sum of the digits of a given number
Find the sum of the digits of a given number
Click me to definition of Sum of digits
Code:
clear echo ----------------------------------- echo '\tSum of Digits' echo ----------------------------------- echo Enter the n value read n sum=0 while [ $n -gt 0 ] do x=$(expr $n % 10) n=$(expr $n / 10) sum=$(expr $sum + $x) done echo The Sum of Digits is $sum
Output:
-----------------------------------
Sum of Digits
-----------------------------------
Enter the n value
123
The Sum of Digits is 6
1 comment:
Unknown
30 July 2018 at 10:11
what does expr means?
Reply
Delete
Replies
Reply
Add comment
Load more...
‹
›
Home
View web version
what does expr means?
ReplyDelete