RosettaCodeData/Task/Arithmetic-Integer/Ballerina/arithmetic-integer.ballerina

25 lines
816 B
Plaintext

import ballerina/io;
function divmod(int a, int b) returns [int, int] {
return [a / b, a % b];
}
function pow(int n, int e) returns int {
if e < 1 { return 1; }
int prod = 1;
foreach int i in 1...e { prod *= n; }
return prod;
}
public function main() returns error? {
int a = check int:fromString(io:readln("first number: "));
int b = check int:fromString(io:readln("second number: "));
io:println("sum: ", a + b);
io:println("difference: ", a - b);
io:println("product: ", a * b);
io:println("integer quotient: ", a / b); // rounds towards zero
io:println("remainder: ", a % b); // sign matches sign of first operand
io:println("exponentiation: ", pow(a, b));
io:println("divmod ", divmod(a, b));
}