You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Hamza elkhatri 4ed04e41ec Update README.md 2 years ago
..
README.md Update README.md 2 years ago

README.md

array-sum

Instructions

Write a function that takes an array of numbers and returns the sum of all the numbers in the array.

  • If the array is empty, the function should return 0.

Expected function

func SumArray(numbers []int) int {
    // your code here
}

Usage

Here is a possible program to test your function:

package main

import (
    "fmt"
)

func main(){
    fmt.Println(SumArray([]int{1,2,3,4,5}))
    fmt.Println(SumArray([]int{}))
    fmt.Println(SumArray([]int{-1,-2,-3,-4,-5}))
    fmt.Println(SumArray([]int{-1,2,3,4,-5}))
}

and the output should be:

$ go run . 
15
0
-15
3