Solver Addition of signed numbers
Algebra
->
Signed-numbers
-> Solver Addition of signed numbers
Log On
Algebra: Operations with Signed Numbers
Section
Solvers
Solvers
Lessons
Lessons
Answers archive
Answers
Source code of 'Addition of signed numbers'
This Solver (Addition of signed numbers)
was created by by
ichudov(507)
:
View Source
,
Show
,
Put on YOUR site
About ichudov
:
I am not a paid tutor, I am the owner of this web site!
==section input This is the <B>addition</B> solver. There is also a separate <A HREF=subtraction-of-signed-numbers.solver>subtraction</A> solver. Calculate and explain: *[input a=4] <FONT SIZE=+3 COLOR=red>+</FONT> *[input b=-2]. ==section solution perl $sum = $a+$b; if( $b < 0 ) { print "$b is a negative number. As you know, addition of a negative number is equivalent to SUBTRACTION of its opposite (positive number). In our case, adding $b is equivalent to SUBTRACTING " . (-$b) . ". {{{$a+ $b = $a-" . (-$b) . "}}} The difference between $a and " . (-$b) . " is $sum. That's your answer.\n\n\n"; } else { print "In this instance, since $b is a positive number, we simply need to perform the addition operation. $a+$b = $sum."; } my $minx = -10; $minx = $a if $a < $minx; $minx = $b if $b < $minx; $minx = $sum if $sum < $minx; $minx--; my $maxx = 10; $maxx = $a if $a > $maxx; $maxx = $b if $b > $maxx; $maxx = $sum if $sum > $maxx; $maxx++; print "{{{ number_line( 400, $minx, $maxx, $a, $b, $sum ) }}}"; ==section output sum ==section check a=5 b=-3 sum=2