Welcome to Dream.In.Code
Become an Expert!

Join 137,429 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,901 people online right now. Registration is fast and FREE... Join Now!




Tcl-i cannot find the error:Can somebody help me...

 
Reply to this topicStart new topic

Tcl-i cannot find the error:Can somebody help me..., i have did this in Jcreator but cannot in Tcl

senyorita
13 Jan, 2008 - 05:59 AM
Post #1

New D.I.C Head
*

Joined: 5 Sep, 2007
Posts: 9


My Contributions
i have compile this coding in JCreator and get the output...the output should look like this:215 960 1220 1775

but when i try to transfer the source code in TCl i cannot find where is the error> Can somebody help me solve my problem.
CODE

set size 5;

proc mkmatrix {rows cols} {
    set count 1;
    set mx [list]
      for { set i 0 } { $i < $rows } { incr i } {
    set row [list]
    for { set j 0 } { $j < $cols } { incr j } {
       lappend row $count;
       incr count;
       }
         lappend mx $row;
     }
      return $mx;
}

    proc mmult {m1 m2} {
         set cols [lindex $m2 0]
           foreach row1 $m1 {
              set row [list]
            set i 0
            foreach - $cols {
               set elem 0
                foreach elem1 $row1 row2 $m2 {
                  set elem [expr {$elem + $elem1 * [lindex $row2 $i]}]
                }
                lappend row $elem
                  incr i
               }
              lappend result $row
       }
       return $result
}

proc main {} {
      global argv size
      set num [lindex $argv 0]
       if {$num < 1} {
      set num 1
      }

      set m1 [mkmatrix $size $size]
      set m2 [mkmatrix $size $size]
      while {$num > 0} {
          incr num -1
          set m [mmult $m1 $m2]
      }

      puts "[lindex [lindex $m 0] 0] [lindex [lindex $m 2] 3] [lindex [lindex $m 3] 2] [lindex [lindex $m 4] 4]"
}

main


This post has been edited by William_Wilson: 13 Jan, 2008 - 07:23 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/5/08 04:55AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month