Arithmetic/Integer: Difference between revisions
Content added Content deleted
Underscore (talk | contribs) m (→{{header|Perl 6}}: Spelling.) |
m (→{{header|JavaScript}}: spidermonkey's javascript implementation has print/readline) |
||
Line 446: | Line 446: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
In order to get user input, this solution {{works with|JScript}}, however the arithmetic operators are the same for any version of JavaScript. |
In order to get user input, this solution {{works with|JScript}} or {{works with|SpiderMonkey}}, however the arithmetic operators are the same for any version of JavaScript. |
||
Note that JavaScript division returns a float, even if the operands are integers. |
Note that JavaScript division returns a float, even if the operands are integers. |
||
<lang javascript> |
<lang javascript>var a = parseInt(get_input("Enter an integer"), 10); |
||
⚫ | |||
⚫ | |||
⚫ | |||
var a = parseInt(get_input("Enter an integer"), 10); |
|||
var b = parseInt(get_input("Enter an integer"), 10); |
var b = parseInt(get_input("Enter an integer"), 10); |
||
Line 463: | Line 458: | ||
WScript.Echo("product: a * b = " + (a * b)); |
WScript.Echo("product: a * b = " + (a * b)); |
||
WScript.Echo("quotient: a / b = " + (a / b)); |
WScript.Echo("quotient: a / b = " + (a / b)); |
||
WScript.Echo("remainder: a % b = " + (a % b)); |
WScript.Echo("remainder: a % b = " + (a % b)); |
||
function get_input(prompt) { |
|||
output(prompt); |
|||
try { |
|||
⚫ | |||
} catch(e) { |
|||
return readline(); |
|||
} |
|||
⚫ | |||
function output(prompt) { |
|||
try { |
|||
⚫ | |||
} catch(e) { |
|||
print(prompt); |
|||
} |
|||
}</lang> |
|||
output: |
output: |
||
⚫ | |||
<pre>d:\glennj>cscript basic_arith.js |
|||
cscript basic_arith.js |
|||
Microsoft (R) Windows Script Host Version 5.7 |
|||
Copyright (C) Microsoft Corporation. All rights reserved. |
|||
⚫ | |||
-147 |
-147 |
||
Enter an integer |
Enter an integer |