Jump to content

Arithmetic/Integer: Difference between revisions

+Forth
m (cleaner formatting)
(+Forth)
Line 35:
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]]==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.