Jump to content

Arithmetic/Integer: Difference between revisions

m
whitespace, minor corrections
(Pari/GP)
m (whitespace, minor corrections)
Line 1:
{{Task|Basic language learning}}[[Category:Arithmetic operations]]{{basic data operation}}Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling. For quotient, indicate how it rounds (e.g. towards 0, towards negative infinity, etc.). For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.
{{Task|Basic language learning}}[[Category:Arithmetic operations]]
{{basic data operation}}
Get two integers from the user, and then output the sum, difference, product, integer quotient and remainder of those numbers. Don't include error handling. For quotient, indicate how it rounds (e.g. towards 0, towards negative infinity, etc.). For remainder, indicate whether its sign matches the sign of the first operand or of the second operand, if they are different.
 
Also include the exponentiation operator if one exists.
Line 78 ⟶ 76:
 
=={{header|Aikido}}==
<lang aikido>var a = 0
 
var a = 0
var b = 0
stdin -> a // read int from stdin
Line 89 ⟶ 85:
println ("a*b=" + (a * b))
println ("a/b=" + (a / b))
println ("a%b=" + (a % b))</lang>
 
</lang>
 
=={{header|ALGOL 68}}==
{{trans|C}}
 
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}
 
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of FORMATted transput}}
Line 388 ⟶ 380:
 
=={{header|Eiffel}}==
{{works with|SmartEiffel}} version |2.4}}
 
In a file called main.e:
<lang eiffel>class MAIN
Line 631 ⟶ 622:
A to the power of B = 16E-4 </lang>
 
== {{header|Icon and Unicon }}==
==={{headerworks with|Unicon}}===
==={{header|Icon}}===
 
<lang Icon>procedure main()
writes("Input 1st integer a := ")
Line 647 ⟶ 637:
write(" a ^ b = ",a^b)
end</lang>
 
==={{header|Unicon}}===
This Icon solution works in Unicon.
 
=={{header|Inform 7}}==
Line 716 ⟶ 703:
 
=={{header|JavaScript}}==
{{works with|JScript}}
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.
{{works with|SpiderMonkey}}
 
Note that the operators work the same in all versions of JavaScript; the requirement for specific implementations is in order to get user input.
<lang javascript>var a = parseInt(get_input("Enter an integer"), 10);
var b = parseInt(get_input("Enter an integer"), 10);
Line 933 ⟶ 921:
And 0&2 = 0
Or 0!2 = 1</lang>
 
 
=={{header|NSIS}}==
All Arithmetic in NSIS is handled by the [http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.10.2 IntOp] instruction. It is beyond the scope of this task to implement user input (a fairly involved task), so I will be providing hard-coded values simulating the user input, with the intention of later adding the user-input piece.
<lang nsis>Function Arithmetic
Function Arithmetic
Push $0
Push $1
Line 961 ⟶ 947:
Pop $1
Pop $0
FunctionEnd</lang>
</lang>
 
=={{header|Objeck}}==
<lang objeck>bundle Default {
bundle Default {
class Arithmetic {
function : Main(args : System.String[]) ~ Nil {
Line 982 ⟶ 966:
}
}
}</lang>
}
</lang>
 
=={{header|OCaml}}==
Line 1,028 ⟶ 1,011:
 
=={{header|PARI/GP}}==
<lang parigp>arith(a,b)={
print(a+b);
print(a-b);
Line 1,067 ⟶ 1,050:
=={{header|Perl 6}}==
{{works with|Rakudo|#21 "Seattle"}}
 
<lang perl6>my Int $a = floor $*IN.get;
my Int $b = floor $*IN.get;
Line 1,131 ⟶ 1,113:
 
=={{header|PostScript}}==
<lang ps>/arithInteger {
/yx exch def
/arithInteger{
/xy exch def
x y expadd =
/y exch def
x y addsub =
x y submul =
x y mulidiv =
x y idivmod =
x y modexp =
} def</lang>
x y exp =
}def
</lang>
=={{header|PowerShell}}==
<lang powershell>$a = [int] (Read-Host First Number)
Line 1,387 ⟶ 1,367:
println("a * b = " + (a * b));
println("quotient of a / b = " + (a / b)); // truncates towards 0
println("remainder of a / b = " + (a % b)); // same sign as first operand</lang>
</lang>
 
=={{header|Scheme}}==
Line 1,617 ⟶ 1,596:
VBScript's variables are all Variants. What starts out as an integer may be converted to something else if the need arises.
 
=====Implementation=====
<lang vb>option explicit
option explicit
dim a, b
wscript.stdout.write "A? "
Line 1,635 ⟶ 1,613:
wscript.echo "a \ b=", a \ b
wscript.echo "a mod b=", a mod b
wscript.echo "a ^ b=", a ^ b</lang>
</lang>
 
=====Another Implementation=====
Gives the same output for the same input. Inspired by Python version.
<lang vb>option explicit
option explicit
dim a, b
wscript.stdout.write "A? "
Line 1,654 ⟶ 1,630:
for each op in split("+ - * / \ mod ^", " ")
wscript.echo "a",op,"b=",eval( "a " & op & " b")
next</lang>
</lang>
 
=====Invocation=====
<pre>
C:\foo>arithmetic.vbs
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.