Jump to content

Arithmetic/Integer: Difference between revisions

add JavaScript
(added PowerShell)
(add JavaScript)
Line 444:
System.out.println("remainder of a / b = " + (a % b)); // same sign as first operand
}</lang>
 
=={{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.
 
Note that JavaScript division returns a float, even if the operands are integers.
<lang javascript>function get_input(prompt) {
WScript.Echo(prompt);
return WScript.StdIn.readLine();
}
 
var a = parseInt(get_input("Enter an integer"));
var b = parseInt(get_input("Enter an integer"));
 
WScript.Echo("a = " + a);
WScript.Echo("b = " + b);
WScript.Echo("sum: a + b = " + (a + b));
WScript.Echo("difference: a - b = " + (a - b));
WScript.Echo("product: a * b = " + (a * b));
WScript.Echo("quotient: a / b = " + (a / b));
WScript.Echo("remainder: a % b = " + (a % b));</lang>
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.
 
Enter an integer
-147
Enter an integer
63
a = -147
b = 63
sum: a + b = -84
difference: a - b = -210
product: a * b = -9261
quotient: a / b = -2.3333333333333335
remainder: a % b = -21</pre>
 
=={{header|Logo}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.