Recent Post

Example 10: Swapping The Positions Of Two Numbers

#!/usr/bin/tclsh

puts "Please enter the first number:"
gets stdin firstNum
puts "Please enter the second number"
gets stdin secNum

proc swapNum {a b} {
	puts "Input: [ list $a $b]"
	set a [ expr $a + $b]
	set b [ expr $a - $b]
	set a [ expr $a - $b]
	puts "Output: [ list $a $b]"
}

swapNum $firstNum $secNum
Output:
Please enter the first number:
34
Please enter the second number:
56
Input: 34 56
Output: 56 34

Comments