Arithmetic Progressions
Arithmetic progressions explains about a series with a common difference.
Here we are going to write a file named ap.tcl and then we will run it as, tclsh ap.tcl
# a = first term
# an = nth term
# d = common difference
#
# nth term of a series
proc nthAP {a d n} {
set an [expr {$a + ($n - 1) * $d}];
return $an;
}
# Sum of n terms of a series
proc sumAP {a d n} {
set sum [expr {0.5 * $n * ($a + [nthAP $a $d $n])}];
return $sum;
}
puts "a=5, d=2, n=6, an: [nthAP 5 2 6]";
puts "a=5, d=2, n=6, sum: [sumAP 5 2 6]";
Happy reading and thnk you. Meet you soon.
Comments
Post a Comment