Arithmetic/Integer: Difference between revisions
Content added Content deleted
m (→{{header|DOS Batch File}}: language tag) |
(added PowerShell) |
||
Line 637: | Line 637: | ||
printf(a div b, 'a div b = %p\n'); |
printf(a div b, 'a div b = %p\n'); |
||
printf(a mod b, 'a mod b = %p\n'); |
printf(a mod b, 'a mod b = %p\n'); |
||
=={{header|PowerShell}}== |
|||
<lang powershell>$a = [int] (Read-Host First Number) |
|||
$b = [int] (Read-Host Second Number) |
|||
Write-Host "Sum: $($a + $b)" |
|||
Write-Host "Difference: $($a - $b)" |
|||
Write-Host "Product: $($a * $b)" |
|||
Write-Host "Quotient: $($a / $b)" |
|||
Write-Host "Quotient, explicitly rounded: $([Math]::Round($a / $b))" |
|||
Write-Host "Remainder: $($a % $b)"</lang> |
|||
Numbers are automatically converted to accomodate for the result. This means not only that Int32 will be expanded to Int64 but also that a non-integer quotient will cause the result to be of a floating-point type. |
|||
The remainder has the sign of the first operand. |
|||
No exponentiation operator exists, but can be worked around with the .NET BCL: |
|||
<lang powershell>[Math]::pow($a, $b)</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |