Ad

initializes a variable sum to store the cumulative sum. Then, it uses a for loop to iterate over all numbers from 1 to num - 1. For each number, it checks if it is divisible by either 3 or 5 using the modulus operator. If it is, the number is added to the sum. Finally, the function returns the sum.

Code
Diff
  • package kata
    
    func Multiple3And5(num int) int {
      sum := 0
    	for i := 1; i < num; i++ {
    		if i%3 == 0 || i%5 == 0 {
    			sum += i
    		}
    	}
    	return sum
    }
    • package kata
    • func Multiple3And5(number int) int {
    • func Multiple3And5(num int) int {
    • sum := 0
    • for i := 1; i < num; i++ {
    • if i%3 == 0 || i%5 == 0 {
    • sum += i
    • }
    • }
    • return sum
    • }