Arithmetic/Integer: Difference between revisions

Content added Content deleted
m (cleaner formatting)
(+Forth)
Line 35: Line 35:
std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n";
std::cout << "a/b = " << a/b << ", remainder " << a%b << "\n";
}
}

==[[Forth]]==
[[Category:Forth]]
To keep the example simple, the word takes the two numbers from the stack. '''/mod''' returns two results; the stack effect is ( a b -- a%b a/b ).
: arithmetic ( a b -- )
cr ." a=" over . ." b=" dup .
cr ." a+b=" 2dup + .
cr ." a-b=" 2dup - .
cr ." a*b=" 2dup * .
cr ." a/b=" 2dup /mod .
cr ." a mod b = " . cr ;


==[[Pascal]]==
==[[Pascal]]==