on
TCL
- Get link
- X
- Other Apps
#!/usr/bin/tclsh
puts "Enter a number: "
gets stdin number
set sum 0
scan $number %d number
while {$number > 0} {
set sum [ expr $sum + $number % 10]
set number [expr $number / 10]
}
puts "Sum of the digits of $number is: $sum"
Enter a number:
00124
Sum of the digits of 00124 is: 7
Enter a number:
7600102
Sum of the digits of 7600102 is: 16
Comments
Post a Comment