task_url stringlengths 30 116 | task_name stringlengths 2 86 | task_description stringlengths 0 14.4k | language_url stringlengths 2 53 | language_name stringlengths 1 52 | code stringlengths 0 61.9k |
|---|---|---|---|---|---|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #FutureBasic | FutureBasic |
window 1, @"Integer Arithmetic", ( 0, 0, 400, 300 )
NSInteger a = 25
NSInteger b = 53
print "addition "a" + "b" = " (a + b)
print "subtraction "a" - "b" = " (a - b)
print "multiplication "a" * "b" = " (a * b)
print "division "a" / "b" = " (a / b)
printf @"float division %ld / %ld = %f", a, b, ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Gambas | Gambas | Public Sub Main()
Dim a, b As String
Dim c, d As Integer
Print "Enter two integer numbers, separated by space:"
Input a, b
c = CInt(a)
d = CInt(b)
Print "Sum: " & (c + d)
Print "Difference:" & (c - d)
Print "Product: " & (c * d)
Print "Integer: " & (c Div d)
Print "Remainder: " & (c Mod d)
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #GAP | GAP | run := function()
local a, b, f;
f := InputTextUser();
Print("a =\n");
a := Int(Chomp(ReadLine(f)));
Print("b =\n");
b := Int(Chomp(ReadLine(f)));
Display(Concatenation(String(a), " + ", String(b), " = ", String(a + b)));
Display(Concatenation(String(a), " - ", String(b), " = ", String(a - b)));
Displ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Genie | Genie | [indent=4]
/*
Arithmethic/Integer, in Genie
valac arithmethic-integer.gs
*/
init:int
a:int = 0
b:int = 0
if args.length > 2 do b = int.parse(args[2])
if args.length > 1 do a = int.parse(args[1])
print @"a+b: $a plus $b is $(a+b)"
print @"a-b: $a minus $b is $(a-b)"
print @"a*b: $a... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #GEORGE | GEORGE | R (m) ;
R (n) ;
m n + P;
m n - P;
m n × P;
m n div P;
m n rem P; |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Go | Go | package main
import "fmt"
func main() {
var a, b int
fmt.Print("enter two integers: ")
fmt.Scanln(&a, &b)
fmt.Printf("%d + %d = %d\n", a, b, a+b)
fmt.Printf("%d - %d = %d\n", a, b, a-b)
fmt.Printf("%d * %d = %d\n", a, b, a*b)
fmt.Printf("%d / %d = %d\n", a, b, a/b) // truncates towards ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Groovy | Groovy | def arithmetic = { a, b ->
println """
a + b = ${a} + ${b} = ${a + b}
a - b = ${a} - ${b} = ${a - b}
a * b = ${a} * ${b} = ${a * b}
a / b = ${a} / ${b} = ${a / b} !!! Converts to floating point!
(int)(a / b) = (int)(${a} / ${b}) = ${(int)(a / b)} ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Harbour | Harbour | procedure Test( a, b )
? "a+b", a + b
? "a-b", a - b
? "a*b", a * b
// The quotient isn't integer, so we use the Int() function, which truncates it downward.
? "a/b", Int( a / b )
// Remainder:
? "a%b", a % b
// Exponentiation is also a base arithmetic operation
? "a**b", a ** b
return |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Haskell | Haskell | main = do
a <- readLn :: IO Integer
b <- readLn :: IO Integer
putStrLn $ "a + b = " ++ show (a + b)
putStrLn $ "a - b = " ++ show (a - b)
putStrLn $ "a * b = " ++ show (a * b)
putStrLn $ "a to the power of b = " ++ show (a ** b)
putStrLn $ "a to the power of b = " ++ show (a ^ b)
putStrLn $ "a to the po... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Haxe | Haxe | class BasicIntegerArithmetic {
public static function main() {
var args =Sys.args();
if (args.length < 2) return;
var a = Std.parseFloat(args[0]);
var b = Std.parseFloat(args[1]);
trace("a+b = " + (a+b));
trace("a-b = " + (a-b));
trace("a*b = " + (a*b));
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #HicEst | HicEst | DLG(Edit=A, Edit=B, TItle='Enter numeric A and B')
WRITE(Name) A, B
WRITE() ' A + B = ', A + B
WRITE() ' A - B = ', A - B
WRITE() ' A * B = ', A * B
WRITE() ' A / B = ', A / B ! no truncation
WRITE() 'truncate A / B = ', INT(A / B) ! truncates toward... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #HolyC | HolyC | I64 *a, *b;
a = Str2I64(GetStr("Enter your first number: "));
b = Str2I64(GetStr("Enter your second number: "));
if (b == 0)
Print("Error: The second number must not be zero.\n");
else {
Print("a + b = %d\n", a + b);
Print("a - b = %d\n", a - b);
Print("a * b = %d\n", a * b);
Print("a / b = %d\n", a / b); /... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #i | i | main
a $= integer(in(' ')); ignore
b $= integer(in('\n')); ignore
print("Sum:" , a + b)
print("Difference:", a - b)
print("Product:" , a * b)
print("Quotient:" , a / b) // rounds towards zero
print("Modulus:" , a % b) // same sign as first operand
print("Exponent:" , a ^ b)
} |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Icon_and_Unicon | Icon and Unicon | procedure main()
writes("Input 1st integer a := ")
a := integer(read())
writes("Input 2nd integer b := ")
b := integer(read())
write(" a + b = ",a+b)
write(" a - b = ",a-b)
write(" a * b = ",a*b)
write(" a / b = ",a/b, " rounds toward 0")
write(" a % b = ",a%b, " remainder sign matches a")
write(" a ^ b = ",a^b)
end |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Ada | Ada | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Main is
procedure divisor_count_and_sum
(n : Positive; divisor_count : out Natural; divisor_sum : out Natural)
is
I : Positive := 1;
J : Natural;
begin
divisor_count := 0;
divi... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Inform_7 | Inform 7 | Enter Two Numbers is a room.
Numerically entering is an action applying to one number. Understand "[number]" as numerically entering.
The first number is a number that varies.
After numerically entering for the first time:
now the first number is the number understood.
After numerically entering for the second... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #J | J | calc =: + , - , * , <.@% , |~ , ^ |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #ALGOL_68 | ALGOL 68 | BEGIN # find arithmetic numbers - numbers whose average divisor is an integer #
# i.e. sum of divisors MOD count of divisors = 0 #
INT max number = 500 000; # maximum number we will consider #
[ 1 : max number ]INT d sum;
[ 1 : max number ]INT d count;
# all po... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Java | Java | import java.util.Scanner;
public class IntegerArithmetic {
public static void main(String[] args) {
// Get the 2 numbers from command line arguments
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int sum = a + b; // The result of a... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #BASIC | BASIC | LET n = 1
DO
LET div = 1
LET divcnt = 0
LET sum = 0
DO
LET quot = n/div
IF quot < div THEN EXIT DO
IF REMAINDER(n, div) = 0 THEN
IF quot = div THEN !n IS a square
LET sum = sum+quot
LET divcnt = divcnt+1
EXIT DO
ELSE
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #JavaScript | JavaScript | var a = parseInt(get_input("Enter an integer"), 10);
var b = parseInt(get_input("Enter an integer"), 10);
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("qu... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #C | C | #include <stdio.h>
void divisor_count_and_sum(unsigned int n, unsigned int* pcount,
unsigned int* psum) {
unsigned int divisor_count = 1;
unsigned int divisor_sum = 1;
unsigned int power = 2;
for (; (n & 1) == 0; power <<= 1, n >>= 1) {
++divisor_count;
divis... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #jq | jq | # Lines which do not have two integers are skipped:
def arithmetic:
split(" ") | select(length > 0) | map(tonumber)
| if length > 1 then
.[0] as $a | .[1] as $b
| "For a = \($a) and b = \($b):\n" +
"a + b = \($a + $b)\n" +
"a - b = \($a - $b)\n" +
"a * b = \($a * $b)\n" +
"a/b|floo... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Jsish | Jsish | "use strict";
/* Arthimetic/Integer, in Jsish */
var line = console.input();
var nums = line.match(/^\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*/);
var a = Number(nums[1]);
var b = Number(nums[2]);
puts("A is ", a, ", B is ", b);
puts("Sum A + B is ", a + b);
puts("Difference A - B is ", a - b);
puts("Pr... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #C.2B.2B | C++ | #include <cstdio>
void divisor_count_and_sum(unsigned int n,
unsigned int& divisor_count,
unsigned int& divisor_sum)
{
divisor_count = 0;
divisor_sum = 0;
for (unsigned int i = 1;; i++)
{
unsigned int j = n / i;
if (j < i)
break;
if (i * j != n)
continue;
divisor_sum +=... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Julia | Julia | function arithmetic (a = parse(Int, readline()), b = parse(Int, readline()))
for op in [+,-,*,div,rem]
println("a $op b = $(op(a,b))")
end
end |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Kotlin | Kotlin | // version 1.1
fun main(args: Array<String>) {
val r = Regex("""-?\d+[ ]+-?\d+""")
while(true) {
print("Enter two integers separated by space(s) or q to quit: ")
val input: String = readLine()!!.trim()
if (input == "q" || input == "Q") break
if (!input.matches(r)) {
... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Factor | Factor | USING: combinators formatting grouping io kernel lists
lists.lazy math math.functions math.primes math.primes.factors
math.statistics math.text.english prettyprint sequences
tools.memory.private ;
: arith? ( n -- ? ) divisors mean integer? ;
: larith ( -- list ) 1 lfrom [ arith? ] lfilter ;
: arith ( m -- seq ) larit... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #FreeBASIC | FreeBASIC | ' Rosetta Code problem: https://rosettacode.org/wiki/Arithmetic_numbers
' by Jjuanhdez, 06/2022
Dim As Double t0 = Timer
Dim As Integer N = 1, ArithCnt = 0, CompCnt = 0
Dim As Integer Div, DivCnt, Sum, Quot
Print "The first 100 arithmetic numbers are:"
Do
Div = 1 : DivCnt = 0 : Sum = 0
Do
Quot = N /... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #LabVIEW | LabVIEW |
{def arithmetic
{lambda {:x :y}
{S.map {{lambda {:x :y :op}
{br}applying :op on :x & :y returns {:op :x :y}} :x :y}
+ - * / % pow max min = > <}}}
-> arithmetic
{arithmetic 8 12}
->
applying + on 8 & 12 returns 20
applying - on 8 & 12 returns -4
applying * on 8 & 12 returns 96
ap... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Delphi | Delphi |
{{works with| Delphi-6 or better}}
program ArithmeiticNumbers;
{$APPTYPE CONSOLE}
procedure ArithmeticNumbers;
var N, ArithCnt, CompCnt, DDiv: integer;
var DivCnt, Sum, Quot, Rem: integer;
begin
N:= 1; ArithCnt:= 0; CompCnt:= 0;
repeat
begin
DDiv:= 1; DivCnt:= 0; Sum:= 0;
while true do
begin
Quot:= N d... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Lambdatalk | Lambdatalk |
{def arithmetic
{lambda {:x :y}
{S.map {{lambda {:x :y :op}
{br}applying :op on :x & :y returns {:op :x :y}} :x :y}
+ - * / % pow max min = > <}}}
-> arithmetic
{arithmetic 8 12}
->
applying + on 8 & 12 returns 20
applying - on 8 & 12 returns -4
applying * on 8 & 12 returns 96
ap... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Go | Go | package main
import (
"fmt"
"math"
"rcu"
"sort"
)
func main() {
arithmetic := []int{1}
primes := []int{}
limit := int(1e6)
for n := 3; len(arithmetic) < limit; n++ {
divs := rcu.Divisors(n)
if len(divs) == 2 {
primes = append(primes, n)
arithme... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Lasso | Lasso | local(a = 6, b = 4)
#a + #b // 10
#a - #b // 2
#a * #b // 24
#a / #b // 1
#a % #b // 2
math_pow(#a,#b) // 1296
math_pow(#b,#a) // 4096 |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #LFE | LFE |
(defmodule arith
(export all))
(defun demo-arith ()
(case (: io fread '"Please enter two integers: " '"~d~d")
((tuple 'ok (a b))
(: io format '"~p + ~p = ~p~n" (list a b (+ a b)))
(: io format '"~p - ~p = ~p~n" (list a b (- a b)))
(: io format '"~p * ~p = ~p~n" (list a b (* a b)))
(:... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #J | J | factors=: {{ */@>,{(^ [:i.1+])&.>/__ q:y}}
isArith=: {{ (= <.) (+/%#) factors|y}}"0 |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Julia | Julia | using Primes
function isarithmetic(n)
f = [one(n)]
for (p,e) in factor(n)
f = reduce(vcat, [f*p^j for j in 1:e], init=f)
end
return rem(sum(f), length(f)) == 0
end
function arithmetic(n)
i, arr = 1, Int[]
while length(arr) < n
isarithmetic(i) && push!(arr, i)
i += 1
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Liberty_BASIC | Liberty BASIC |
input "Enter the first integer: "; first
input "Enter the second integer: "; second
print "The sum is " ; first + second
print "The difference is " ; first -second
print "The product is " ; first *second
if second <>0 then print "The integer quotient is " ; int( first /second); " (rounds towards 0)" else print "Di... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Pascal | Pascal |
program ArithmeiticNumbers;
procedure ArithmeticNumbers;
var N, ArithCnt, CompCnt, DDiv: longint;
var DivCnt, Sum, Quot, Rem: longint;
begin
N:= 1; ArithCnt:= 0; CompCnt:= 0;
repeat
begin
DDiv:= 1; DivCnt:= 0; Sum:= 0;
while true do
begin
Quot:= N div DDiv;
Rem:=N mod DDiv;
if Quot < DDiv then break;... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #LIL | LIL | # Arithmetic/Integer, in LIL
write "Enter two numbers separated by space: "
if {[canread]} {set line [readline]}
print
set a [index $line 0]
set b [index $line 1]
print "A is $a"", B is $b"
print "Sum A + B is [expr $a + $b]"
print "Difference A - B is [expr $a - $b]"
print "Product A *... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Perl | Perl | use strict;
use warnings;
use feature 'say';
use List::Util <max sum>;
use ntheory <is_prime divisors>;
use Lingua::EN::Numbers qw(num2en num2en_ordinal);
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub table { my $t = 10 * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Lingo | Lingo | -- X, Y: 2 editable field members, shown as sprites in the current GUI
x = integer(member("X").text)
y = integer(member("Y").text)
put "Sum: " , x + y
put "Difference: ", x - y
put "Product: " , x * y
put "Quotient: " , x / y -- Truncated towards zero
put "Remainder: " , x mod y -- Result has sign of left ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Little | Little | # Maybe you need to import the mathematical funcions
# from Tcl with:
# eval("namespace path ::tcl::mathfunc");
void main() {
int a, b;
puts("Enter two integers:");
a = (int)(gets(stdin));
b = (int)(gets(stdin));
puts("${a} + ${b} = ${a+b}");
puts("${a} - ${b} = ${a-b}");
puts("${a} * ... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Phix | Phix | with javascript_semantics
sequence arithmetic = {1}
integer composite = 0
function get_arithmetic(integer nth)
integer n = arithmetic[$]+1
while length(arithmetic)<nth do
sequence divs = factors(n,1)
if remainder(sum(divs),length(divs))=0 then
composite += length(divs)>2
... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Python | Python | def factors(n: int):
f = set([1, n])
i = 2
while True:
j = n // i
if j < i:
break
if i * j == n:
f.add(i)
f.add(j)
i += 1
return f
arithmetic_count = 0
composite_count = 0
n = 1
while arithmetic_count <= 1000000:
f = factors(n)
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #LiveCode | LiveCode | ask "enter 2 numbers (comma separated)"
if it is not empty then
put item 1 of it into n1
put item 2 of it into n2
put sum(n1,n2) into ai["sum"]
put n1 * n2 into ai["product"]
put n1 div n2 into ai["quotient"] -- truncates
put n1 mod n2 into ai["remainder"]
put n1^n2 into ai["power"]
com... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Logo | Logo | to operate :a :b
(print [a =] :a)
(print [b =] :b)
(print [a + b =] :a + :b)
(print [a - b =] :a - :b)
(print [a * b =] :a * :b)
(print [a / b =] int :a / :b)
(print [a mod b =] modulo :a :b)
end |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Raku | Raku | use Prime::Factor;
use Lingua::EN::Numbers;
my @arithmetic = lazy (1..∞).hyper.grep: { my @div = .&divisors; (@div.sum / +@div).narrow ~~ Int }
say "The first { .Int.&cardinal } arithmetic numbers:\n", @arithmetic[^$_].batch(10)».fmt("%{.chars}d").join: "\n" given 1e2;
for 1e3, 1e4, 1e5, 1e6 {
say "\nThe { .I... |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Rust | Rust | fn divisor_count_and_sum(mut n: u32) -> (u32, u32) {
let mut divisor_count = 1;
let mut divisor_sum = 1;
let mut power = 2;
while (n & 1) == 0 {
divisor_count += 1;
divisor_sum += power;
power <<= 1;
n >>= 1;
}
let mut p = 3;
while p * p <= n {
let mut... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #LSE64 | LSE64 | over : 2 pick
2dup : over over
arithmetic : \
" A=" ,t over , sp " B=" ,t dup , nl \
" A+B=" ,t 2dup + , nl \
" A-B=" ,t 2dup - , nl \
" A*B=" ,t 2dup * , nl \
" A/B=" ,t 2dup / , nl \
" A%B=" ,t % , nl |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Lua | Lua | local x = io.read()
local y = io.read()
print ("Sum: " , (x + y))
print ("Difference: ", (x - y))
print ("Product: " , (x * y))
print ("Quotient: " , (x / y)) -- Does not truncate
print ("Remainder: " , (x % y)) -- Result has sign of right operand
print ("Exponent: " , (x ^ y)) |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #Wren | Wren | import "./math" for Int, Nums
import "./fmt" for Fmt
import "./sort" for Find
var arithmetic = [1]
var primes = []
var limit = 1e6
var n = 3
while (arithmetic.count < limit) {
var divs = Int.divisors(n)
if (divs.count == 2) {
primes.add(n)
arithmetic.add(n)
} else {
var mean = Nums... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #M2000_Interpreter | M2000 Interpreter |
MODULE LikeCommodoreBasic {
\\ ADDITION: EUCLIDEAN DIV# & MOD# AND ** FOR POWER INCLUDING ^
10 INPUT "ENTER A NUMBER:"; A%
20 INPUT "ENTER ANOTHER NUMBER:"; B%
30 PRINT "ADDITION:";A%;"+";B%;"=";A%+B%
40 PRINT "SUBTRACTION:";A%;"-";B%;"=";A%-B%
50 PRINT "MULTIPLICATION:";A%;"*";B%;... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #M4 | M4 | eval(A+B)
eval(A-B)
eval(A*B)
eval(A/B)
eval(A%B) |
http://rosettacode.org/wiki/Arithmetic_numbers | Arithmetic numbers | Definition
A positive integer n is an arithmetic number if the average of its positive divisors is also an integer.
Clearly all odd primes p must be arithmetic numbers because their only divisors are 1 and p whose sum is even and hence their average must be an integer. However, the prime number 2 is not an arithmetic ... | #XPL0 | XPL0 | int N, ArithCnt, CompCnt, Div, DivCnt, Sum, Quot;
[Format(4, 0);
N:= 1; ArithCnt:= 0; CompCnt:= 0;
repeat Div:= 1; DivCnt:= 0; Sum:= 0;
loop [Quot:= N/Div;
if Quot < Div then quit;
if Quot = Div and rem(0) = 0 then \N is a square
[Sum:= Sum+Quot; DivC... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Maple | Maple |
DoIt := proc()
local a := readstat( "Input an integer: " ):
local b := readstat( "Input another integer: " ):
printf( "Sum = %d\n", a + b ):
printf( "Difference = %d\n", a - b ):
printf( "Product = %d\n", a * b ):
printf( "Quotient = %d\n", iquo( a, b, 'c' ) ):
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Mathematica.2FWolfram_Language | Mathematica/Wolfram Language | a = Input["Give me an integer please!"];
b = Input["Give me another integer please!"];
Print["You gave me ", a, " and ", b];
Print["sum: ", a + b];
Print["difference: ", a - b];
Print["product: ", a b];
Print["integer quotient: ", Quotient[a, b]];
Print["remainder: ", Mod[a, b]];
Print["exponentiation: ", a^b]; |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Mathcad | Mathcad | disp("integer a: "); a = scanf("%d", 1);
disp("integer b: "); b = scanf("%d", 1);
a+b
a-b
a*b
floor(a/b)
mod(a,b)
a^b |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #MATLAB_.2F_Octave | MATLAB / Octave | disp("integer a: "); a = scanf("%d", 1);
disp("integer b: "); b = scanf("%d", 1);
a+b
a-b
a*b
floor(a/b)
mod(a,b)
a^b |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Maxima | Maxima | block(
[a: read("a"), b: read("b")],
print(a + b),
print(a - b),
print(a * b),
print(a / b),
print(quotient(a, b)),
print(remainder(a, b)),
a^b
); |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #MAXScript | MAXScript | x = getKBValue prompt:"First number"
y = getKBValue prompt:"Second number:"
format "Sum: %\n" (x + y)
format "Difference: %\n" (x - y)
format "Product: %\n" (x * y)
format "Quotient: %\n" (x / y)
format "Remainder: %\n" (mod x y) |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Mercury | Mercury |
:- module arith_int.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module int, list, string.
main(!IO) :-
io.command_line_arguments(Args, !IO),
( if
Args = [AStr, BStr],
string.to_int(AStr, A),
string.to_int(BStr, B)
th... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Metafont | Metafont | string s[];
message "input number a: ";
s1 := readstring;
message "input number b: ";
s2 := readstring;
a := scantokens s1;
b := scantokens s2;
def outp(expr op) =
message "a " & op & " b = " & decimal(a scantokens(op) b) enddef;
outp("+");
outp("-");
outp("*");
outp("div");
outp("mod");
end |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #min | min | (concat dup -> ' prepend "$1 -> $2" swap % puts!) :show
("Enter an integer" ask int) 2 times ' prepend
('+ '- '* 'div 'mod) quote-map ('show concat) map cleave |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #.D0.9C.D0.9A-61.2F52 | МК-61/52 | П1 <-> П0
+ С/П
ИП0 ИП1 - С/П
ИП0 ИП1 * С/П
ИП0 ИП1 / [x] С/П
ИП0 ^ ИП1 / [x] ИП1 * - С/П
ИП1 ИП0 x^y С/П |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #ML.2FI | ML/I | MCSKIP "WITH" NL
"" Arithmetic/Integer
"" assumes macros on input stream 1, terminal on stream 2
MCSKIP MT,<>
MCINS %.
MCDEF SL SPACES NL AS <MCSET T1=%A1.
MCSET T2=%A2.
a + b = %%T1.+%T2..
a - b = %%T1.-%T2..
a * b = %%T1.*%T2..
a / b = %%T1./%T2..
a rem b = %%T1.-%%%T1./%T2..*%T2...
Division is truncated to t... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Modula-2 | Modula-2 | MODULE ints;
IMPORT InOut;
VAR a, b : INTEGER;
BEGIN
InOut.WriteString ("Enter two integer numbers : "); InOut.WriteBf;
InOut.ReadInt (a);
InOut.ReadInt (b);
InOut.WriteString ("a + b = "); InOut.WriteInt (a + b, 9); InOut.WriteLn;
InOut.WriteString ("a - b = "); InOut.WriteInt (a - b... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Modula-3 | Modula-3 | MODULE Arith EXPORTS Main;
IMPORT IO, Fmt;
VAR a, b: INTEGER;
BEGIN
a := IO.GetInt();
b := IO.GetInt();
IO.Put("a+b = " & Fmt.Int(a + b) & "\n");
IO.Put("a-b = " & Fmt.Int(a - b) & "\n");
IO.Put("a*b = " & Fmt.Int(a * b) & "\n");
IO.Put("a DIV b = " & Fmt.Int(a DIV b) & "\n");
IO.Put("a MOD b = " & ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #MUMPS | MUMPS | Arith(first,second) ; Mathematical operators
Write "Plus",?12,first,"+",second,?25," = ",first+second,!
Write "Minus",?12,first,"-",second,?25," = ",first-second,!
Write "Multiply",?12,first,"*",second,?25," = ",first*second,!
Write "Divide",?12,first,"/",second,?25," = ",first/second,!
Write "Int Divide",?12,firs... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Nanoquery | Nanoquery | print "Number 1: "
x = int(input())
print "Number 2: "
y = int(input())
println format("Sum: %d", x + y)
println format("Difference: %d", x - y)
println format("Product: %d", x * y)
println format("Quotient: %f", x / y)
println format("Remainder: %d", x % y)
println format("Power: %d", x ^ y) |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Nemerle | Nemerle | using System;
class Program
{
static Main(args : array[string]) : void
{
def a = Convert.ToInt32(args[0]);
def b = Convert.ToInt32(args[1]);
Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
Console.WriteLine("{0} * ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #NetRexx | NetRexx | /* NetRexx */
options replace format comments java crossref symbols binary
say "enter 2 integer values separated by blanks"
parse ask a b
say a "+" b "=" a + b
say a "-" b "=" a - b
say a "*" b "=" a * b
say a "/" b "=" a % b "remaining" a // b "(sign from first operand)"
say a "^" b "=" a ** b
return
|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #NewLISP | NewLISP | ; integer.lsp
; oofoe 2012-01-17
(define (aski msg) (print msg) (int (read-line)))
(setq x (aski "Please type in an integer and press [enter]: "))
(setq y (aski "Please type in another integer : "))
; Note that +, -, *, / and % are all integer operations.
(println)
(println "Sum: " (+ x y))
(println "Di... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Nial | Nial | arithmetic is OP A B{[first,last,+,-,*,quotient,mod,power] A B} |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Nim | Nim | import parseopt, strutils
var
opt: OptParser = initOptParser()
str = opt.cmdLineRest.split
a: int = 0
b: int = 0
try:
a = parseInt(str[0])
b = parseInt(str[1])
except ValueError:
quit("Invalid params. Two integers are expected.")
echo("a : " & $a)
echo("b : " & $b)
echo("a + b : " & $(... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #NSIS | NSIS | Function Arithmetic
Push $0
Push $1
Push $2
StrCpy $0 21
StrCpy $1 -2
IntOp $2 $0 + $1
DetailPrint "$0 + $1 = $2"
IntOp $2 $0 - $1
DetailPrint "$0 - $1 = $2"
IntOp $2 $0 * $1
DetailPrint "$0 * $1 = $2"
IntOp $2 $0 / $1
DetailPrint "$0 / $1 = $2"
DetailPrint "Rounding is toward negative infinity"
IntOp ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Oberon-2 | Oberon-2 |
MODULE Arithmetic;
IMPORT In, Out;
VAR
x,y:INTEGER;
BEGIN
Out.String("Give two numbers: ");In.Int(x);In.Int(y);
Out.String("x + y >");Out.Int(x + y,6);Out.Ln;
Out.String("x - y >");Out.Int(x - y,6);Out.Ln;
Out.String("x * y >");Out.Int(x * y,6);Out.Ln;
Out.String("x / y... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Objeck | Objeck | bundle Default {
class Arithmetic {
function : Main(args : System.String[]) ~ Nil {
DoArithmetic();
}
function : native : DoArithmetic() ~ Nil {
a := IO.Console->GetInstance()->ReadString()->ToInt();
b := IO.Console->GetInstance()->ReadString()->ToInt();
IO.Console->GetInstance... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #OCaml | OCaml | let _ =
let a = read_int ()
and b = read_int () in
Printf.printf "a + b = %d\n" (a + b);
Printf.printf "a - b = %d\n" (a - b);
Printf.printf "a * b = %d\n" (a * b);
Printf.printf "a / b = %d\n" (a / b); (* truncates towards 0 *)
Printf.printf "a mod b = %d\n" (a mod b) (* same sign as first operand *... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Oforth | Oforth | : integers (a b -- )
"a + b =" . a b + .cr
"a - b =" . a b - .cr
"a * b =" . a b * .cr
"a / b =" . a b / .cr
"a mod b =" . a b mod .cr
"a pow b =" . a b pow .cr
; |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Ol | Ol |
(define a 8)
(define b 12)
(print "(+ " a " " b ") => " (+ a b))
(print "(- " a " " b ") => " (- a b))
(print "(* " a " " b ") => " (* a b))
(print "(/ " a " " b ") => " (/ a b))
(print "(quotient " a " " b ") => " (quot a b)) ; same as (quotient a b)
(print "(remainder " a " " b ") => " (rem a b)) ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Onyx | Onyx | # Most of this long script is mere presentation.
# All you really need to do is push two integers onto the stack
# and then execute add, sub, mul, idiv, or pow.
$ClearScreen { # Using ANSI terminal control
`\e[2J\e[1;1H' print flush
} bind def
$Say { # string Say -
`\n' cat print flush
} bind def
$ShowPreambl... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Openscad | Openscad | echo (a+b); /* Sum */
echo (a-b); /* Difference */
echo (a*b); /* Product */
echo (a/b); /* Quotient */
echo (a%b); /* Modulus */ |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Oz | Oz | declare
StdIn = {New class $ from Open.file Open.text end init(name:stdin)}
fun {ReadInt}
{String.toInt {StdIn getS($)}}
end
A = {ReadInt}
B = {ReadInt}
in
{ForAll
["A+B = "#A+B
"A-B = "#A-B
"A*B = "#A*B
"A/B = "#A div B %% truncates towards 0
"remainder "#A mod B %% has the sa... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Panda | Panda | a=3 b=7 func:_bbf__number_number_number =>f.name.<b> '(' a b ')' ' => ' f(a b) nl |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PARI.2FGP | PARI/GP | arith(a,b)={
print(a+b);
print(a-b);
print(a*b);
print(a\b);
print(a%b);
print(a^b);
}; |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Pascal | Pascal | program arithmetic(input, output)
var
a, b: integer;
begin
readln(a, b);
writeln('a+b = ', a+b);
writeln('a-b = ', a-b);
writeln('a*b = ', a*b);
writeln('a/b = ', a div b, ', remainder ', a mod b);
writeln('a^b = ',Power(a,b):4:2); {real power}
writeln('a^b = ',IntPower(a,b):4:2); {integer power}
end. |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Perl | Perl | my $a = <>;
my $b = <>;
print
"sum: ", $a + $b, "\n",
"difference: ", $a - $b, "\n",
"product: ", $a * $b, "\n",
"integer quotient: ", int($a / $b), "\n",
"remainder: ", $a % $b, "\n",
"exponent: ", $a ** $b, "\n"
; |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Phix | Phix | with javascript_semantics
include pGUI.e
Ihandle lab, tab, res, dlg
constant fmt = """
a = %d
b = %d
a + b = %d
a - b = %d
a * b = %d
a / b = %g (does not truncate)
remainder(a,b) = %d (same sign as first operand)
power(a,b) = %g
"""
function valuechanged_cb(Ihandle tab)
string s = IupGetAttribute(tab,"VALUE")
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Phixmonti | Phixmonti | def printOp
swap print print nl
enddef
8 var a 3 var b
"a = " a printOp
"b = " b printOp
"a + b = " a b + printOp
"a - b = " a b - printOp
"a * b = " a b * printOp
"int(a / b) = " a b / int printOp
"a mod b = " a b mod printOp
"a ^ b = " a b power printOp |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PHL | PHL | module arith;
extern printf;
extern scanf;
@Integer main [
@Pointer<@Integer> a = alloc(4);
@Pointer<@Integer> b = alloc(4);
scanf("%i %i", a, b);
printf("a + b = %i\n", a::get + b::get);
printf("a - b = %i\n", a::get - b::get);
printf("a * b = %i\n", a::get * b::get);
printf("a / b = %i\n", a::get / b::ge... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PHP | PHP | <?php
$a = fgets(STDIN);
$b = fgets(STDIN);
echo
"sum: ", $a + $b, "\n",
"difference: ", $a - $b, "\n",
"product: ", $a * $b, "\n",
"truncating quotient: ", (int)($a / $b), "\n",
"flooring quotient: ", floor($a / $b), "\n",
"remainder: ", $a % $... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PicoLisp | PicoLisp | (de math (A B)
(prinl "Add " (+ A B))
(prinl "Subtract " (- A B))
(prinl "Multiply " (* A B))
(prinl "Divide " (/ A B)) # Trucates towards zero
(prinl "Div/rnd " (*/ A B)) # Rounds to next integer
(prinl "Modulus " (% A B)) # Sign of the first operand
(prinl "Power "... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Piet | Piet |
command stack
in(int) A
duplicate AA
duplicate AAA
duplicate AAAA
duplicate AAAAA
in(int) BAAAAA
duplicate BBAAAAA
duplicate BBBAAAAA
duplicate BBBBAAAAA
duplicate BBBBBAAAAA
push 9 9BBBBBAAAAA
push 1 19BBBBBAAAAA
roll BBBBAAAABA
push 7 7BBBBAAAABA
push 1 17BBBBAAAABA
roll BBBAAABABA
push 5... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PL.2FI | PL/I |
get list (a, b);
put skip list (a+b);
put skip list (a-b);
put skip list (a*b);
put skip list (trunc(a/b)); /* truncates towards zero. */
put skip list (mod(a, b)); /* Remainder is always positive. */
put skip list (rem(a, b)); /* Sign can be negative. */ |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Plain_English | Plain English | To run:
Start up.
Demonstrate integer arithmetic.
Wait for the escape key.
Shut down.
To demonstrate integer arithmetic:
Write "Enter a number: " to the console without advancing.
Read a number from the console.
Write "Enter another number: " to the console without advancing.
Read another number from the console.
Sho... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Pop11 | Pop11 | ;;; Setup token reader
vars itemrep;
incharitem(charin) -> itemrep;
;;; read the numbers
lvars a = itemrep(), b = itemrep();
;;; Print results
printf(a + b, 'a + b = %p\n');
printf(a - b, 'a - b = %p\n');
printf(a * b, 'a * b = %p\n');
printf(a div b, 'a div b = %p\n');
printf(a mod b, 'a mod b = %p\n'); |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PostScript | PostScript | /arithInteger {
/x exch def
/y exch def
x y add =
x y sub =
x y mul =
x y idiv =
x y mod =
x y exp =
} def |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PowerShell | 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 "Q... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #11l | 11l | [Int] array
array.append(1)
array.append(3)
array[0] = 2
print(array[0]) // retrieve first element in an array
print(array.last) // retrieve last element in an array
print(array.pop()) // pop last item in an array
print(array.pop(0)) // pop first item in an array
V size = 10
V myArray = [0] * size // create single-... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.