Finding The Number Of Digits In A Number Part 1

 Do you need to find the number of digits in a number?

 Here we are going to write a file named digitcountp1.tcl and then we will run it as, 

tclsh digitcountp1.tcl 

#digitcountp1.tcl

# This procedure counts the number of digits

# in a number.

proc dcnt {num} {

set number $num;

set digicnt 0;

if {$number != 0} {

if {$number < 0} {

set number [expr {$number * -1}];

}

while {$number != 0} {

incr digicnt;

set number [expr {$number / 10}];

}

}

return $digicnt;

}


Happy reading and thank you. Meet you soon.

Comments

Popular posts from this blog

Bash Shell In Linux

Creating An Animation Using A Text Editor

expr command In TCL