I.a. Fractorial Computation
Program in tcl to obtain the value of 10! = 10 * 9 * ... * 1?
proc Factorial {x} { set result 1 ... FILL IN ... return $result } set result [Factorial 10] puts "$result"prompt>ns lab2a.tcl
I.b. Multiplying and Dividing
Program in otcl to multiply or divide integer and real numbers.
Class Real Real instproc init {x} { $self instvar value_ set value_ $x } Real instproc multiply {x} { ... FILL IN ... } Real instproc divide {x} { $self instvar value_ puts [expr $value_ / [$x set value_]] } Class Integer -superclass Real Integer instproc divide {x} { ... FILL IN ... } set realA [new Real 12.3] set realB [new Real 0.5] $realA multiply $realB $realA divide $realB set integerA [new Integer 12] set integerB [new Integer 5] $integerA multiply $integerB $integerA divide $integerBprompt>ns lab2a.tcl
Multiplying Complex Numbers (a+bi)
References: