Includes
file maths.gom:
fn abs(x: Int) -> Int
{
if (x < 0) {
return (x * -1);
}
return x;
}
fn factorial(x: Int) -> Int
{
if (x < 1) {
return x * factorial(x - 1);
}
return 1;
}
fn sum(a: [Int]) -> Int
{
s: Int = 0;
for (i: Int = 0; i < len(a); i++) {
s += a[i];
}
return s;
}
fn power(x: Int, pow:Int) -> Int
{
if (x == 0) {
return 0;
}
if (y < 0) {
return (power(x, y + 1) / x);
}
return (power(x, y - 1) * x);
}file main.gom:
Output:
Include the sum function from the math lib.
Declare a list of Int.
Call the sum function of the list a and return the result.
Last updated
Was this helpful?