Mistivia 3 月之前
父節點
當前提交
05b6011d5b
共有 1 個文件被更改,包括 21 次插入0 次删除
  1. 21 0
      0006/main.tcl

+ 21 - 0
0006/main.tcl

@@ -0,0 +1,21 @@
+proc square {x} {
+    return [expr {$x * $x}]
+}
+
+proc sum_of {x} {
+    set result 0
+    for {set i 1} {$i <= $x} {incr i} {
+        set result [expr {$result + $i}]
+    }
+    return $result
+}
+
+proc sum_of_square {x} {
+    set result 0
+    for {set i 1} {$i <= $x} {incr i} {
+        set result [expr {$result + [square $i]}]
+    }
+    return $result
+}
+
+puts [expr {[square [sum_of 100]] - [sum_of_square 100]}]